sanjaybangalore.gns
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.
0
of 0 vote
we can compress it using Huffman tree method.... i dont think we cud do it by palindrome
- sanjaybangalore.gns March 28, 2015Comment hidden because of low score. Click to expand.
0
of 0 vote
Algo
1. ittrate once and get the info's of pairs where it has very high difference : ex ladder from 61 to 99 make a list and of all pair ladders and sort them descending order of difference ex (99-61)
2. now choose top most non looping pairs from above data in consideration and fill up the space between ladders by n (0<n<7) blocks which doesn't contains snake.
complexity - {step 1} + {step 2} ={ (o)n + (o)mlogm (m - number of ladders) }+ {constant} =~ (o)n
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
I use stack here
- sanjaybangalore.gns April 16, 2015algo
buff[k]
k=0;
push(a[0])
i=1;
while ( end of array a[]) {
if(a[i]<top()) ;
push(a[i]);
else {
//maintain lowest element in top of the stack
while(a[i]>(buff[k++]=pop()));
push(a[i]);
}
}
complexity -> o(n)
finally if the array buff[] is sorted then its a preorder representation of BST