Archive for the ‘Job Interviews’ Category.

Merge 2 Binary Search Trees

Write a program to mergeĀ  two binary search trees, in O(n) time with O(1) space

Least Common Ancestor in a Tree with only Parent pointers

Given a tree with only children pointing to the parents, find the least common ancestor of 2 nodes.

Find a cycle in a linked list

How would you find a cycle in a linked list? Optimize for speed.

Find Lowest Common Ancestor of 2 nodes

One of the common, yet tricky interview question is to find the lowest common ancestor node for given 2 nodes in

A. Binary Tree

B. N-ary tree

Maximum rectangle inside a Histogram

Find the maximum rectangle completely contained inside a histogram where each bars has a width of 1 unit. The heights of the bars of the histograms are given in an array e.g. {4,2,10,8,12,13,15,8,6} and they have a fixed width w = 1, say. The rectangles formed here are: 4X1, 2X9, 10X1, 8X6, 12X3, 13X2, 15X1, 8X6, 6X7 Thus, max-area rectangle = 8X6 = 48

Find the longest palindrome

Find the longest palindrome in a given string

Find all valid words in a string

Given a String, find out all the valid dictionary words contained in the string.

Reverse Linked List

Write a program to reverse a linked list

1. With recursion

2. Without Recursion

Sort an array of 0’s , 1’s and 2’s

Given a array of 0’s,1’s and 2’s. Sort the array.

Find Median of 2 Sorted Arrays

Find Median of 2 sorted arrays