Microsoft Interview Question for Software Engineer / Developers






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

Use two indexes, one at the beginning and one at the end.

while(start < end) {
 if (a[start] + a[end] > number)
  end--;
 else
  if(a[start] + a[end] < number)
   start++;
  else
   break; // found 
}

- S February 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thanks S for the answer

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

I think s approach also based on fact that array is sorted thats
we are increasing end and start pointer.

- Raj January 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Paras: Given a sorted array, your approach is definitely higher in complexity. However if we are given an unsorted array, the sorting itself will take O (n lgn). Then your approach will also be O (n lgn). No loss no gain. However S's approach is recommended even in that case!

- souravghosh.btbg February 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use Hashtable to achieve better time-complexity.
Just Iterate through an array i.e. remainder= NumberGiven - A[i] and search the hashTable for remainder.
I hope, it does work.
or Just check all possibilities.

- NS March 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Find the index (k) of the number in array.
2) Parse a[] up to k-1 by with n/2(n/2-1) iterations to verify. The complexity will be O(n2/2)

- Leks March 14, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Just another idea (though the complexity will be high)
for each element a[i] in the array
do a binary search on the array for number-a[i].
if found then these two numbers are the pair.

- Paras February 26, 2011 | Flag Reply


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