Archive for November 2009

Reverse the words in a sentence

Write a program to reverse the words in a string.String is represented as an array.

Input: hello my world

Expected Output: world my hello

Check whether a linked list is a palindrome

Given a linked list, find out whether it is a palindrome or not

0’s and 1’s Only Matrix Interview Questions

Given an MXN Matrix consisting of only elements 0’s or 1’s.

Find

1. Largest square matrix with 1’s

2. Largest rectagle with 1’s

3. Largest Square with borders made of 1’s

4. Largest Rectangle with borders made of 1’s

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 intersection of 2 arrays

How do you find out intersection between two arrays
Case 1:  One array huge compared to the other array
Case 2: One array sorted
Case 3: Both arrays sorted
Case 4: Unsorted and of equal length

Find the number of rotations performed on a sorted array

Given a sorted array rotated n times. Find the number of right side rotations performed on the array.
Example:
input: 678912345
expected output: 4 (rotating 123456789 4 times we will get the input)

Find the smallest window that covers a set of words

Given a document and a query of K words, how do u find the smallest window that covers all the words at least once in that document?

Find all valid words in a string

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