Microsoft Interview Question for Software Engineer / Developers






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

Assuming intervals are sorted.

lets say the element in question to be k.

now divide the n intervals in half, Consider n/2 interval to be [a,b]

Now k belongs in the interval [a,b] if (a-x)(b-x) <= 0

if(x > b)
then do binary search in the right side of the intervals of [a,b]
if(x < a)
then do binary search in the left side of the intervals of [a,b]

Complexity would be here O(logn) as is the case with binary search.

- algooz April 23, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@algooz
you also can assume n=2.
then you get the answer

- Anonymous October 07, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@algooz
you also can assume n=2.
then you get the answer

- Anonymous October 07, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@algooz
you also can assume n=2.
then you get the answer

- Anonymous October 07, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

algooz
you also can assume n=2.
then you get the answer

- Anonymous October 07, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Anonymous,

What is your answer ?

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

Use segment tree

- Aditya October 11, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

let me write simplistic psudocode for this to begin with.....
Assumtptions:
- all start and end times are +ves
- set of intervals given is unsorted, and is represented as a pair of numbers denoting start and end time.

for each interval I from set of all intervals
if ( Is <= elemnt && Ie >= elemnt )
return I

O(N) solution.

on 2nd look this looks too simple, there might be something missing.

- morpheus February 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

LOL
its trivial in O(n) ... so the only missing thing is to do it in less then O(N)

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

By an interval tree, it is O(lgn)!

- Anonymous May 26, 2010 | 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