Microsoft Interview Questions
0of 0 votesYou are a startup trying to design a new mobile online music player.
(startup => you need to differentiate yourself from the existing music players)
0of 0 votesAn airline carrier is losing a lot of bags. You have been assigned to help them out. What would you do?
0of 0 votesYou are at the center of n*n*n cube if n is odd and somewhere near center if n is even, print all possible paths to reach the surface of the cube
0of 0 votes>Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, M(x1, y1) == -1 && M(x2, y2) == -1 && |x1-x2|+|y1-y2|=1 <=> they are connected
Example:
-1 0 -1 0 0
-1 -1 0 -1 -1
0 0 0 0 -1
0 0 0 -1 -1
0 0 0 -1 0
0 -1 0 0 0
0 -1 0 0 0
Output: 4. And they are:
-1
-1 -1
-1
-1 -1
-1
-1 -1
-1
-1
-1
My idea is to scan the matrix.
Initialization:
count = 0.
For every item in the matrix, do the following three tests.
(1) If it's 0, skip
> (2) If it's -1, check its four neighbors. If there is a neighbor whose
value is not 0 and -1, assign the value of this neighbor to the current item. Otherwise, `count++`, ant then assign `count` to the current item.
>
> (3) If it's not 0 and -1, assign the value of current item to its four
neighbors whose value is -1.
Can anyone help me verify this solution?
0of 0 votesGive a basic over view of designing a linkedlist in Java
0of 0 votesGiven an Array say, a [0,1,2,6,3,4] and lets say x=5..
Return true for all the values which add up to value of x like 2+3, 1+4 etc; for everything else return false.
0of 0 votesHow do we store data at x(Row),y(column) of an excel sheet into a 1 dimensional buffer of fixed size.
x can be any row and y can be any column..
0of 0 votesGiven 2 strings, return the max number that can be formed by joining them.
For example, if the strings are:
45 and 456
2 numbers are possible
45456
45645
The output should be
45645
0of 0 votesGiven a binary tree find the difference in height between the closest leaf to the root and the furthest leaf from the root. You cannot use recursion since the tree is very deep and would cause a stack overflow.
0of 0 votesGiven an integer array, sort the integer array such that the concatenated integer of the result array is max. e.g. [4, 94, 9, 14, 1] will be sorted to [9,94,4,14,1] where the result integer is 9944141
0of 0 votesGiven an unsorted array.
With each number, we can associated a sum which is equal to the sum of all the numbers, less than the current number.
We've to find the total sum of all those numbers.
e.g. unsorted array :1, 5, 3, 6, 4.
for a[0]=1, sum[0]=0
for a[1]=5, sum[1]=1
for a[2]=3, sum[2]=1
for a[3]=6, sum[3]=1+5+3
for a[4]=4, sum[4]=1+3
total sum =sum[0]+sum[1]+sum[2]+sum[3]+sum[4] = 15
0of 0 votesFind the first common ancestor of two nodes in a binary tree (note not a BST).
0of 0 votesIn Excel sheet rows are marked using integer numbers like 1,2,3 but the columns are marked using characters. Like A, B and C.
so here column 0 = A (assuming column starting with 0)
column 1 = B
column 25 = Z
column 26 = AA
column 100 = CW
Q. Write a program to give the string representation of column for given integer.
0of 0 votesGiven a sum find(print) all 2 numbers and their index positions from an un-ordered array that add up the sum value. 1 4 4 3 7 5 8 as array and sum =8 .
So here the code should print 1 (index 0) + 7(index 4)
4(index 1)+ 4(index2), and so on..
0of 0 votesHow do you test a Calendar? (eg. An outlook calendar or google calendar)
0of 0 votesGiven an array { -2 3 5 0 -3 7 -1}. Sort the array in such a way that array should contain -ve numbers first and then zero and then all +ve numbers. (Note: order of +ve number and order of -ve numbers should be same after sorting). For ex: the o/p of above array is {-2 -3 -1 0 3 5 7}
0of 0 votesGiven 3 sorted arrays. Find(x,y,z), (where x is from 1st array, y is from 2nd array, and z is from 3rd array), such that Max(x,y,z) - Min(x,y,z) is minimum.
0of 0 votesDesign a Date class that represents a US date. Write add and subtract operation using the class. Optimize the operations.
0of 0 votesGiven an array of integers [2,1,3, 5, 7, 6], re arrange elements such that either even numbers in even locations or odd numbers in odd locations. i.e [2,1,6,5,7,3] in O(n)
0of 0 votes#include <iostream>
class C {
private:
int num;
public:
C(int a) : num(a) {}
int get_val() const;
};
//changes are not allowed in below code
int C::get_val() const {
num++;
return num;
}
int main() {
C obj(29);
std::cout << obj.get_val() << std::endl;
}
The question was to make the above code work you can make changes only inside class C
0of 0 votesgiven string is of the form "abcd1234defgh8965" then output should be "a1b2c3d4 d8e9f6g5" with O(n) time??
0of 0 votesGiven an array [a1b2c3d4] convert to [abcd1234] with 0(1) space and O(n) time
0of 0 votesGiven two lists sorted in increasing order, create and return a new list representing the intersection of the two lists. The new list should be made with its own memory — the original lists should not be changed.
For example, let the first linked list be 1->2->3->4->6 and second linked list be 2->4->6->8, then your function should create and return a third list as 2->4->6.
0of 0 votesGiven two numbers represented by two lists, write a function that returns sum list. The sum list is list representation of addition of two input numbers ?
Example First List: 5->6->3 // represents number 365
Second List: 8->4->2 // represents number 248
Resultant list: 3->1->6 //
Note :Any Carry forward should also be added as the new node . Any Comments on the code below
0of 0 votesYou have given n numbers from 1 to n. You have to sort numbers with increasing number of set bits.
for ex: n=5.
output: 1,2,4,3,5
Note: If you have two number with equal number of set bits, then number with lowest value come first in the output.
0of 0 votesGiven an unsorted array, how to divide them into two equal arrays whose sum of difference is minimum.
Can it be done in o(n)?
0of 0 votesWrite a program to print the code structure.
(Basically it was to print the nodes of Tree in DFS. )
0of 0 votesWrite an API to find valid IP address.
(Asked followup questions like which kind or IP format, return type, range specific, etc.)
0of 0 votesDesign SkyDrive. (open ended question. )
0of 0 votesImplement IEnumerable<string> foo(IEnumerable<string> a, IEnumerable<string> b) such that foo returns string in either a or b but not both
