Archive for the ‘Microsoft’ 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

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.

Write a program to say whether a string is a rotation of another

Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1. example if S1=ABCD then BCDA,CDAB etc are rotations of S1.

Kth Smallest element of a Binary Search Tree

Given a Binary Search Tree, write a program to print the kth smallest element

Find the missing number

This is a very common interview questions and comes in various forms. The most common one is of the following format
Problem 1
Given an array of 999 distinct integers ranging from 1 to 1000 including. Find which number is missing. Restrictions: loop over the array only once, can’t allocate an additional array.

Another version of the problem is where 2 numbers are missing.
Problem 2
Given an array of 998 distinct integers ranging from 1 to 1000 including. Find which 2 numbers are missing.

Restrictions: loop over the array only once, can’t allocate an additional array.