Mirror of a Tree: Mirror of a Binary Tree T is another Binary Tree M(T) with left and right children of all non-leaf nodes interchanged.
Trees in the above figure a...

Share

Given a binary tree (not a binary search tree) and two values say n1 and n2, write a program to find the least common ancestor.
Following is definition of LCA from W...

Share

Given a binary tree, find height of it. Height of empty tree is 0 and height of below tree is 3.
Example Tree
Recommended: Please solve it on “PRACTICE ...

Share

The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two end nodes. The diagram below shows two trees each with dia...

Share

The diameter of a tree is the number of nodes on the longest path between two leaves in the tree. The diagram below shows two trees each with diameter nine, the leave...

Share

Given a Linked List and a number n, write a function that returns the value at the n’th node from end of the Linked List.
For example, if input is below list a...

Share

Given a singly linked list of characters, write a function that returns true if the given list is palindrome, else false.
Recommended: Please solve it on “P...

Share

Given a 2D array, print it in spiral form. See the following examples.
Examples:
Input:
1 2 3 4
5 6 7 8
9 10 11 12
...

Share

Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands
Example:
Input : ma...

Share

The problem is opposite of this post. We are given a Queue data structure that supports standard operations like enqueue() and dequeue(). We need to implement a St...

Share