Microsoft Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
2
of 2 vote

see the introduction to algorithms by carman book O(nlogn) is complexcity...

- DinakaranGct December 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sort the array -- O(nlogn)
then for each element 'a' do a binary search on rest of the array for (sum - a).
Binary search will take logn and we'll have to repeat it for all n elements so nlogn.
so total = nlogn + nlogn = nlogn

- insigniya December 21, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

integer pairs?? does that mean 2 numbers at a time..?? 2 consecutive numbers or just any 2 numbers in the whole array?

- Hetal September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

did you really think msft will ask this kind of retarded question? even a retard like you can do two consecutive integers..

- Anonymous September 20, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sol1 - use hash table - add element in an array then check the diff (m - new element) in hash table.

sol 2 sort an array - pick element from start and end, check if sum is equal to m if not then sum > m then pick next element from last if sum < m, select next element from start

- Anonymous September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorting cannot be considered for this as sorting itself takes O(nlogn).
we can consider the hash table approach and in that case run time would be O(n), Is that acceptable @ gs2005?

- masamushi September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

can some one pls explain the hash approach more clearly .. "add element in an array then check the diff (m - new element) in hash table.
"

- Anonymous September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

He is saying:
-Insert all elements in array into hash table.
-While not end of array
{
Get next element, x, from array.
Look up m-x in hash table, if found break out of loop
}

- Ozgur Ozturk September 09, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use "Counting sort" here (runs in O(n)), because the range is known (range = sum). But the range should be reasonably small.

- Anonymous September 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

In that case what u will take as min and max value.

- Saurabh November 16, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int [] hashArr = {1,3,7,12,2,71,8,9,10,6,4};
int numEle = hashArr.length;
Hashtable ht = new Hashtable();
// Add all the elements to the Hash Table
for(int i=0;i<numEle;i++)
ht.put(i, hashArr[i]);
// Check the difference, sum - i = ex whether in HashTable
int sum = 10;
int diff = 0;
for(int j=0;j<numEle;j++){
diff = sum-hashArr[j];
if(ht.contains(diff))
System.out.println(hashArr[j]+":"+diff);
}

- Anonymous October 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

gs2005: what was your answer, as all of us are trying to make use of hash to get a O(n) solution. do you have any good answer, at least better than our approach.

- xin hu October 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What if the sum is 50.. and the array contents are {25,45,30}... ? First it selects 25 and again searching in hash returns 25.. a pair(25,25) that does not exist..

- Raghav October 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thats a valid point ... hash method fails for this case ... what we can do is also check if (m-new element)== m or not ... if array doesnt contain duplicates .. such cases should be considered invalid

- AB December 21, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

another approach would be to keep a count of each element in hash table and decrementing the count when visited ... this shud take care of duplicates

- AB December 21, 2009 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More