Saturday, October 18, 2008

Problems from thecareerplus

http://www.thecareerplus.com/?page=resources&cat=150

MS interview problem(zz)

Hi Guys,
I went to the Microsoft written test held in EGL, Bangalore today, and the questions that were asked are as follows:

The pattern of the test was they had given 4 questions and we had to answer within 90 min.

So, the questions are:

1. You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.

2. Given an array of integers, {10203004567000}, you have to create a new array which will be like (12345670000000}, without using any other temporary array.

3. (A) Given two Link List on integers which are sorted, you have to merge those two link lists and create a new LinkList which is also sorted.

3. (B) Give few example link lists to test the above implemented Link Lists.

Reverse link

Reverse a linked list iteratively, do it first with single pointers and then do it again with double pointers. Now do it again recursively but not tail-recursive, and then do it again tail-recursively. What do you do if it has a loop?

MS interview problem(zz)

1) Write a function which determines wheather in given array there is a sequence of n or more elements, which have the same value. Example:
n = 3, input[] = { 1,1,1,2,3,4,5 } gives true;
n = 2, input[] = { 5,1,2,2,2,4,5 } gives true;
n = 3, input[] = { 5,2,2,3,2,5,5 } gives false;

2) Write a function which determines, wheather the array is a mirror - reflection - like. Example:

input[] = {1,2,3,2,1} gives true
input[] = {1,2,3,3,2,1} gives true.

Const vs. #define

Advantages of const over #define. When to use which of them?

hints:
const means the data can't be changed while define has no such meaning.
const is used by compiler and define is performed by pre-processor.
const has scope while define can be considerd global.
const variable can be seen from debugger while macro can be seen.
const guarantee the type which macro can't

Stack vs Heap Allocation

Where in memory are a program's static variables stored?

When a program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment, and heap segment. The text segment (sometimes also called the code segment) is where the compiled code of the program itself resides. This is the machine language representation of the program steps to be carried out, including all functions making up the program, both user defined and system.

The remaining two areas of system memory is where storage may be allocated by the compiler for data storage. The stack is where memory is allocated for automatic variables within functions. A stack is a Last In First Out (LIFO) storage device where new storage is allocated and deallocated at only one ``end'', called the Top of the stack.

The heap segment provides more stable storage of data for a program; memory allocated in the heap remains in existence for the duration of a program. Therefore, global variables (storage class external), and static variables are allocated on the heap.

Hash Table vs. Binary Search Tree

When would you use a hash table over a Binary Search Tree?