## Microsoft Interview Questions

- 0of 0 votes
Print elements of a matrix in spiral form.

- 0of 0 votes
Given 2 sorted linked lists, return a linked list that has all the elements and is sorted.

- 0of 0 votes
Given 3 strings "s" ssearch" and "sreplace", search string s for the substring ssearch and for every instance of ssearch you find, replace that part of the string with sreplace

- 0of 0 votes
Given an NxN Boolean matrix, find how many true regions there are in the matrixj

- 0of 0 votes
Create a basic minesweeper game that allows for board creation with custom height, width and number of mines. Create a <click> function that will take in a board location and return whether the user has won, lost, or the number of surrounding mines.

- 0of 0 votes
Given a string, print out all of the unique characters and the number of times it appeared in the string

- 0of 0 votes
What is the smallest number *n* by which the given number *x* must be divided to make it into a perfect square?

`n = find_number( x )`

- 0of 0 votes
Given a singly linked list of integers, write a function in java that returns true if the given list is palindrome, else returns false

- 0of 0 votes
Convert an unordered tree to a binary tree

- 0of 0 votes
merge two binary search trees

- 0of 0 votes
Sort a stack using only one other stack and no recursion.

- 0of 0 votes
Given a dictionary and an char array print all the valid words that are possible using char from the array.

Ex- char[] arr = {'e','o','b', 'a','m','g', 'l'}

Dict - {"go","bat","me","eat","goal", "boy", "run"}

Print - go, me, goal.

We can pre-compute as much we want but the query time must be optimal.

- 1of 1 vote
You are given a function getNum() that returns a random number in the range 1 to 10 million with repetitions. However, it may also return -1 when it no longer provides numbers. Write a function that calls getNum() continuously until it returns -1 (if a repetition, should not store it); as soon as u see -1, stop calling getnum() and print all the numbers seen so far in a sorted way. Condition: You have got very limited memory to work with.

- 1of 1 vote
You have a matrix that is sorted as such: For each value, every index to its right and below it must be larger than the current space's value. Likewise, all entries to its left and above it must be smaller than the current value. How would you go about searching this matrix for a specific number, given its sorted nature?

- 0of 0 votes
Just a disclaimer: I doubt you will ever get this interview question. My interviewer even started off by saying, "Hmm, well this isn't really fair, but..." So don't place too much stock in whether or not you can solve this.

Question: You have a group of pigs and buckets of food for said pigs. There are 1,000 buckets of food, and exactly 1 of them is poisoned. Your goal is to determine, by the end of 1 hour, which bucket is poisoned.

The poison takes 30 minutes to kill a pig, and you'd like to kill as few pigs as possible. The number of pigs you can test is limitless, and you can assign a number to each bucket and each pig so that you know exactly which pig ate from which bucket(s). You determine which buckets to feed to which pigs, but you have no timer and no way to guesstimate the time. What is the minimum number of pigs you need to use to solve the problem?

- 0of 0 votes
You are given an array of positive and negative integers. If a number n at an index is positive, then move forward n steps. Conversely, if it's negative, move backward n steps. Determine if there is a loop in this array.

For example, given the array [2, -1, 1, 2, 2], index 0 maps to index 2, 1 maps to 0, 2 maps to 3, and so on. There is a loop in this array because 0 maps to 2, 2 maps to 3, and 3 maps to 0 (use the modulo operator).

- 0of 0 votes
1. If I say quick sort takes O(e^n ) on the average, would I be wrong?

2. Do you think O( f ) is a good idea for real engineering?

3.Given a choice, what other 'order of' measure would you propose to use ?

4. Do you see a real problem with the modified *order of* ?

5. If you were to sort 10 elements, what sorting method would you have used?

6. If you were to sort 1 trillion unicode characters, what sorting method you would have used?

- 0of 0 votes
The actual problem from question?id=6289136497459200

Implement pow, with :`// Assume C/C++, as of now double pow ( double x, double power )`

No library functions allowed.

Should return : x^power

=== Edit ===

People took it a bit trivially, thus examples should help :`x = pow ( 4, 0.5 ) // x = 2.0 x = pow ( 8, 0.333333333 ) // 1.99999999986137069 x = pow ( 10.1 , 2.13 ) // 137.78582031242644`

- 1of 1 vote
determine whether a word is in a stored list;

the list doesn't fit into memory;

no disk access allowed, for lookups, memory access only;

no false positives allowed, false negatives ok

- 1of 1 vote
A list of words is given and a bigger string given how can we find whether the string is a permutation of the smaller strings.

eg- s= badactorgoodacting dict[]={'actor','bad','act','good'] FALSE

eg- s= badactorgoodacting dict[]={'actor','bad','acting','good'] TRUE

The smaller words themselves don't need to be permuted. The question is whether we can find a ordering of the smaller strings such that if concatenated in that order it gives the larger string

One more constraint - some words from dict[] may also be left over unused

- 0of 0 votes
Suggest a data structure and implement efficient phrase search along with word search in a huge chunk of text.

- 0of 0 votes
Design a system for searching strings in files present on a fileserver under a directory. there won't be any sub-directories. There could be more than thousand/lakhs files. And the file size could be in GBs. The matching line should be written to a single file. user will execute grep "string"

The sub-questions are

1) Design where the application executes on single machine.

2) Design where the application can execute on multiple machine.

3) Where could be the potential bottleneck.

4) What component would be bottleneck if 50 cores and slow disk.

5) What component would be the bottleneck if we 4 cores and fast disks.

- 2of 2 votes
You have two very large numbers that cannot be stored in any available datatypes. How would you multiply them?

How would you multiply more than two numbers?

- 0of 0 votes
How will you implement a dictionary.

- 0of 0 votes
Design a monitoring system for hotel booking site. Proper oops design.

- 0of 0 votes
How do I solve this simple geometrical programming problem?

https://s32.postimg.org/sm75dimol/hurdle1.jpg

- 0of 0 votes
Given an array: 1,2,3 ,5,8,7,6,9,5,7,3,0,5

subarry:5,7

Find the subarray in the large array and return the minimum length and index where you can find the subarray. Note: that the subarray may be present in the large array non-contiguous.

In the above case : the answer is length = 2 and

index = 8

- 0of 0 votes
Suppose you have a matrix in the form of a 2 dimensional array. Write a method to read the rows of the matrix alternatively from right to left, left to right so on and return them as a 1 dimensional array.

for eg:

1 2 3

4 5 6

7 8 9

should return 1 2 3 6 5 4 7 8 9

- 0of 0 votes
how to restrict creation of object inside the function fun

although destructor and constructor is private??

#include <iostream>

class ABC

{

private :

~ABC()

{

}

ABC()

{

std::cout <<"ABC";

}

public:

static void fun()

{

ABC t;

}

};

int main()

{

ABC::fun();

}

- -1of 1 vote
Given a matrix which is spirally sorted. Remove an element and insert another element maintaining the sorted order.