healer0994
BAN USER
Comments (3)
Reputation 0
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 do BFS and at the time of enqueuing a node
check if node number i.e. index of node is between 2^i (inclusive) and 2^i+1 (excluding) then do a count[i] ++;
note : here count is array which contains no of nodes of each level .
also root node is at level 0 and further levels are numbered accordingly ...
Comment hidden because of low score. Click to expand.
0
of 0 vote
isnt anantha's solution more complex .... i mean to check if temp is present in string we could use kmp <at best > ( having O(n)) with some preprocessing that would raise the complexity to above O(n).......
wouldnt it be easy if use the following pseudocode with complexity O(n) :
for(int i=31 to 3000)
if(abs(i-reverse(i))==(9 or 198 or 3087 )
do not print
else
print "i"
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
i guess a new approach would be to take character by character from string and set a bit vector (size 26) index to 1 for every character untill there is a repitition of charac in string ......... and as soon as a repition is found do two things :a) print the charac corresponding to which bit vector has consec 1
b) reset entire bit vector to 0
complexity - O(n^2)
code is as follows :
- healer0994 June 03, 2014