Here’s one I was asked during my interview:
- binary tree, nodes, each node has an ID
- root node of the tree
structure node
{
int id;
node *
left;
node *
right;
}
- problem: given node id 1, and node id 2, determine the
lowest common ancestor of these 2 nodes
- input:
id1, id2, root
- out: node
id of this ancestor node
Read Answers(8) | 31,335 Views |
Today I wrote MS written test. There were 3 questions. 10 marks each.
1. Write a program to output all elements of a binary tree while doing a Breadth First traversal through it.
2.Write a method to combine two two sorted linked list into one in sorted form with out using temporary Node.
void sort(Node* list1,Node* list2)
3.There are set of coins of {50,25,10,5,1} paise in a box.Write a program to find the number of ways a 1 rupee can be created by grouping the paise.
Read Answers(6) | 22,445 Views |
This was asked at Microsoft in January of 2008.
Write a function that takes three integers corresponding to the lengths of sides and returns what kind of triangle can be made out of those 3 sides. (Equilateral, etc)
You must also handle the case where no triangle may be formed from those 3 lengths.
Read Answers(14) | 21,778 Views |
Four people need to cross a rickety rope bridge to get back to their camp at night. Unfortunately, they only have one flashlight and it only has enough light left for seventeen minutes. The bridge is too dangerous to cross without a flashlight, and it’s only strong enough to support two people at any given time. Each of the campers walks at a different speed. One can cross the bridge in 1 minute, another in 2 minutes, the third in 5 minutes, and the slow poke takes 10 minutes to cross. How do the campers make it across in 17 minutes?
Read Answers(11) | 28,103 Views |
Implement the following function, FindSortedArrayRotation,
which takes as its input an array of unique integers that has been sorted
in ascending order, then rotated by an unknown amount X where 0 <=
X <= (arrayLength - 1). An array rotation by amount X moves every
element array[i] to array[(i + X) % arrayLength]. FindSortedArrayRotation discovers and returns X by examining the array.
Consider performance, memory utilization and code clarity and elegance
of the solution when implementing the function.
C++ Prototype
int FindSortedArrayRotation( int
array[], unsigned length )
{
}
C# Prototype
static int FindSortedArrayRotation(
int[] array )
{
}
Read Answers(21) | 23,235 Views |
A solution consists of four balls from a set of four different colors. The user
tries to guess the solution.
If they guess the right color for the right
spot, record it as being in the correct ‘Location’. If it’s the right color,
but the wrong spot, record it as a correct ‘Color’. For example: if the
solution is ‘BGRR’ and the user guesses ‘RGYY’ they have 1 ‘Location’ and 1
‘Color’. A correct solution would be 4 ‘Location’ and 0 ‘Color’.
Write a program to, given a solution and a
guess, calculate the response that we present to the user.
Read Answers(12) | 9,119 Views |
How much does a 747 weigh?
Read Answers(20) | 39,463 Views |
Describe a chicken using a programming language.
Read Answers(12) | 48,787 Views |
How much would you charge for washing all the windows in Seattle?
Read Answers(9) | 32,583 Views |
How many golf balls can fit in a school bus?
Read Answers(34) | 97,758 Views |