Thursday, 4 April 2013

Q) #level-order-traversal #binary-tree
 Reverse level order traversal of a binary tree

                          1
                    2          3
                4     5     6   7

should print   4 5 6 7 2 3 1

Ans) Use stack and store the results of level order traversal. While doing level order traversal make sure  we're traversing right child first and then left child so that finally popping out each elements from the stack will give the required output.

Q) Print all unique rows in a boolean matrix

Q) In an array containing only 1s and 0s, find longest consecutive sequence which contain same number of 1s and 0s
   (Replace 0s with -1s and form a new array with each element having sum till that element. Then the problem reduces to finding longest sequence having sum as zero whose solution is already discussed earlier).

No comments:

Post a Comment