respectmyauthoritah
BAN USER
Comments (3)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
public int getLongest(int[] dp, int n){
if(dp[n]>0) return dp[n];
if(n%2==0) dp[n] = getLongest(dp, n/2) + 1;
else dp[n] = getLongest(dp,3*n + 1) + 1;
return dp[n];
}
public int collatzConjecture(){
int[] dp = new int[100000000];
dp[2] = 1;
int max = 0, maxNum = 1;
for(int i=2;i<=10000;i++){
if(getLongest(dp,i)>max){
max = getLongest(dp,i);
maxNum = i;
}
}
return maxNum;
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
using trie to solve this problem:
1. build a 26-ary trie
2. doing a inorder traversal of this trie
3. find the (closest) next word
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Priority queue represented as a balanced binary heap: the two children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The priority queue is ordered by comparator, or by the elements' natural ordering, if comparator is null: For each node n in the heap and each descendant d of n, n <= d. The element with the lowest value is in queue[0], assuming the queue is nonempty.
- respectmyauthoritah April 27, 2017Why did the interviewer say you're wrong?