Microsoft Interview Question for Software Engineer in Tests






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

How about using BinarySearch? Ar running time of the BinarySearch is o(log n).

Finding the number of elements in the list / finding the mid of the linked list will take o(n) worst case. ~ o(n/2). Hence its o(n) again.

- master December 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Linklist is a serial access data structure , not random access like array. In order to access any node in the linklist we have to traverse from the start of the link list to that node. In array Accessing any element is a O(1) operation where as in linklist it is O(n).

The (log n) efficiency of the binary search is inversely proportional to the access time of the middle element. In binary search we access the middle element log(n) times, as the access time of linklist is O(n) the time complexity of binary search in linklist becomes O(nlogn).

The best inplace solution would be linear search O(n).

- aaaaaa July 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

One can try the slow/fast pointer to reduce the complexity to O(n/x + x) where n is number of nodes and x is size of step.

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

Is it a simple O(n) algo, traversing through the list ? or something special about this question ?

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

Yes its O(n) except that you can terminate the search once you reach a higher value (if sorted in Ascending order)

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

is there any way to do it better than 0(n) ?

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

We may do this in O(n/2) my having 2 pointers corresponding to even and odd elements ..in this way in the worst case also it loop will run for O(n/2) times...

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

your solution also same as above...
becoz if you use two pts even and odd,have to do 4 comparisons inside the loop,in worst case you done n/2 * 4 = 2n comparisons,

in the previous ans,have to do 2 comparisons, in worst case we done n * 2 = 2n comparisons,

so both are same time complexity

- DannY September 21, 2010 | 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