In a Binary Tree, Create Linked Lists of all the nodes at each depth.

Objective: Given a Binary tree create Linked Lists of all the nodes at each depth , say if the tree has height k then create k linked lists.

NOTE : This problem is very similar “Print binary tree, each level in one line

Input: A binary tree

Output: K linked lists if the height of tree is k. Each linked list will have all the nodes of each level.

Example:

Read moreIn a Binary Tree, Create Linked Lists of all the nodes at each depth.

Level Order Traversal, Print each level in separate line.

Objective: Given a Binary tree , Print each level of a tree in separate line.

NOTE : This problem is very similar ” Create Linked Lists of all the nodes at each depth “

Input: A binary tree

Output: Each level of binary tree, in one line

Example:

Read moreLevel Order Traversal, Print each level in separate line.

Rearrange Positive and Negative Numbers of Array On Each Side in O(nlogn)

Objective: Rearrange Positive and Negative Numbers of an Array so that one side you have positive numbers and other side with negative Integers without changing their respective order.

Example : Input :  1 -2 3 -4 5 -6 7 -8 9 -10

ReArranged Output :  -2 -4 -6 -8 -10 1 3 5 7 9

Input: An array with positive and negative numbers

Output: Modified array with positive numbers and negative numbers are on each side of the array.

Approach:

Method 1. One naive approach is to have another array of same size and navigate the input array and one scan place all the negative numbers to the new array and in second scan place all the positive numbers to new array. Here the Space complexity will be O(n). We have a better solution which can solve this in O(1) space.

Method 2: Divide and Conquer

Read moreRearrange Positive and Negative Numbers of Array On Each Side in O(nlogn)

Find The Longest Sequence Of Prefix Shared By All The Words In A String

Objective: Write an algorithm to find The Longest Sequence Of Prefix Shared By All The Words In A String. This interesting problem was asked in the Google interview for software engineer. This problem is bit tricky, it looks difficult but actually it is simple problem.

Input: A String

Output: The longest sequence of prefix common in all the words in a string

Example:

“Bedroom BedClock BedTable BedWall” => “Bed”

Approach:

Read moreFind The Longest Sequence Of Prefix Shared By All The Words In A String