poorvisha
BAN USER
i got your point. the below soln will work for sure..try it!!!
algorithm that solves problem in linear time:
1.store the sum in an array from start till the point.
2.maintain the counts of sum in hash table
3.if there exists sum == 0 in the hash table, count of 0 = count of 0 + 1
4.for sum whose count == 2
no_of_sub-arrays = no_of_sub-arrays + 1;
else
for sum whose count > 2 ,let n = count
no_of_sub-arrays = no_of_sub-arrays + nC2 ,C denotes combination
5.repeat step 4 for all sums in hash table
6.print no_of_sub-arrays.
that's it!!!
jsdude, your idea of pushing null is awesome!!!
but there is a small correction. your code will get struck in an infinite loop because the queue will never become empty. after processing all elements the queue at end will always contain null.
so to fix the problem do the following:
before enqueuing null check if the queue is empty.
if (the queue is empty )
break from the loop
else
enqueue null and continue.
correct me if i am wrong..
the above diagram was not clear so i posted again........
1
/ \
2 3
/ \
4 6
/
5
o/p should contain 4...
but acord., to the prgs posted in this site as well as in other sites o/p will not contain 4.
the best soln is to do bfs and keep track start and end nodes at each level...
please correct if i am wrong............
the above diagram was not clear so i posted again........
1
/ \
2 3
/ \
4 6
/
5
o/p should contain 4...
but acord., to the prgs posted in this site as well as in other sites o/p will not contain 4.
the best soln is to do bfs and keep track start and end nodes at each level...
please correct if i am wrong............
i think this question is asked by the interviewer to check if we are clarifying ambiguity regarding the question.
any person who s good in testing should get to know the requirements at first step.hence if such a qn s asked ask qns to interviewer to make the qn clear.
Repangelwilley8, xyz at Asiatic Solutions
I am Angel J. Willey from Gurnee. I am working as a truck driver in Asiatic Solutions company. I also ...
Repmakaylaangwin, Backend Developer at Abs india pvt. ltd.
I'm part owner of Bloom Floral Land, an Australian floral design company. Life is really short, try to smile ...
*dst = (*src) & (-1 >>(8-nbit)); should be rewritten as *dst = (*src) & (-1 <<(8-nbit));
- poorvisha April 19, 2014