Category Archives: Trees

Longest consecutive sequence in Binary tree

Given a Binary Tree find the length of the longest path which comprises of nodes with consecutive values in increasing order. Every node is considered as a path of length 1. Examples: In below diagram binary tree with longest consecutive path(LCP) are shown : We can solve above problem recursively. At each node we need… Read More »

Flip Binary Tree

Given a binary tree, the task is to flip the binary tree towards right direction that is clockwise. See below examples to see the transformation. In the flip operation, left most node becomes the root of flipped tree and its parent become its right child and the right sibling become its left child and same… Read More »

Find a number in minimum steps

Given an infinite number line from -INFINITY to +INFINITY and we are on zero. We can move n steps either side at each n’th time. 1st time; we can move only 1 step to both ways, means -1 1; 2nd time we can move 2 steps from -1 and 1; -1 : -3 (-1-2) 1(-1+2)… Read More »

Evaluation of Expression Tree

Given a simple expression tree, consisting of basic binary operators i.e., + , – ,* and / and some integers, evaluate the expression tree. Examples: Input : Root node of the below tree Output : 100 Input : Root node of the below tree Output : 110 As all the operators in the tree are… Read More »