Category Archives: Trees

Continuous Tree

A tree is Continuous tree if in each root to leaf path, absolute difference between keys of two adjacent is 1. We are given a binary tree, we need to check if tree is continuous or not. Examples: Input : 3 / \ 2 4 / \ \ 1 3 5 Output: “Yes” // 3->2->1… Read More »

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 »