koolkeshaw
BAN USER
Comments (4)
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
the sector can be painted in order -- W B W W B B
- koolkeshaw July 14, 2013Comment hidden because of low score. Click to expand.
0
of 0 vote
using Kadane's algorithm , we can find a contiguous sub-array whose sum = S.
Now check if product of sub-array =P.
If yes , then update the variable min_length;
(min_length--> stores the requisite minimum length)
Comment hidden because of low score. Click to expand.
0
of 0 vote
Since we require to optimize memory used , so I think iterative solution would be better than recursive.
Iterative approach:-
Solution is similar to iterative level-order-traversal of a tree using a queue .
For each level increment the counter.
Final value of the counter would be the required answer
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
The element at the ith position in the final array will be at position
(i%2)*N + i/2 in the original array
Above logic can further extended for 'k' ;
- koolkeshaw July 14, 2013