Category Archives: Trees

Find maximum level sum in Binary Tree

Given a Binary Tree having positive and negative nodes, the task is to find maximum sum level in it. Examples: Input : 4 / \ 2 -5 / \ /\ -1 3 -2 6 Output: 6 Explanation : Sum of all nodes of 0’th level is 4 Sum of all nodes of 1’th level is… Read More »

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 »