Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

geeksforgeeks.org/archives/2105

- Nithin June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i have a solution and it's O(logn1+logn2)

We may assume that the median is in the first array .

let n=(n1+n2);
if n is odd{
let k=(n+1)/2
else k=n/2
the element m in position i of the first array is the answer only when there
are ( k-1-(i-1) ) elements smaller than it...
we can use binary search method to find the median...
the solution is O(logn1+logn2)

- stupid February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Median of 1st array=m1,and of second array be m2
2.if(m2>m1)
Do a binary search for nearest possible element (m1+m2)/2 in both arrays
O(log n)

- Ash February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Median of 1st array=m1,and of second array be m2
2.if(m2>m1)
Do a binary search for nearest possible element (m1+m2)/2 in array 2 and save it. Do binary search again in array 1 and compare with save. update if possible
O(log n)

- Anonymous February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

First Merge two sorted arrays to get a single sorted array.
Time = ( n + m ) -> Consider it as n.. Hence merging takes O(n) time.

Find Median.
Index of the median element = (int) ((n+m)/2) -> Which can be achieved in constant time..

Hence Solution is of the order O(n) ->

- Vijay Rajanna February 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. compare the median m_a, m_b of two array a, b
2. if same return the median
3. if different,
if m_a > m_b
//remove right half of a, or left half of b;
if length of a > length of b
remove left half of b, meanwhile remove left (length of b/2) elements of a
recursive;
if length of b > length of a
....
if m_a < m_b
....

- StartFromNeg1 February 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this would work very well if both the arrays are of same length

- Anonymous March 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes, this works if both the arrays are of same length

- Anonymous April 27, 2012 | 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