Microsoft Interview Question for Software Engineer in Tests






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

Why not a balanced binary tree? To search for a place to insert and to insert in tree it only takes O(log n) ! Once the book is final, in order traversal can assign page numbers.

- ashishkaila@hotmail.com November 22, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This seems to be the best out of the solutions posted above. At each node, store the number of nodes in the left sub tree and the number of nodes in the right sub tree!
Also store the depth of the left tree and depth of the right tree.
An inorder traversal at any point will give the pages of the book in order. Now, while inserting the precise point of insertions is known. i.e while inserting pg 15 we have to reach the node which has a cumulative of 14 pages. Insert the node. Now use balancing techniques to rebalance the tree

- rahil9800 November 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Maybe priority queue (min heap for example), so you could easily change page number (priority). It will take lg*N time to change page priority.

- Maxim Stepanenko March 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there is no notion of ordering in binary heap. you cant use it.

- Anonymous June 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

could any one explain the question in brief??

- ba March 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

think about adding pages randomly to the book either at the end or in the middle.. suppose there are 20 pages and we insert an extra page after 15 so the ordering of page 15-20 changes to 16-21. Is binary search tree or Linked list an option in such case? what about eliminating duplicates and reordering the pages? if it is just about adding more pages at the end is it easier in BST (lgn) and it takes O(1) in Linked list (adding to the tail), max heap also sounds good..

- rash March 11, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@rash, good answer

- siva.sai.2020 March 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ rash, How come BST time complexity O(log n ).

Let us say page nos
1 2 3 4 5
add a new page at stating of the book, then you have to modify all page nos .

1 2 3 4 5 6

Adding a new page at the starting of the book ,time complexity O(n). you have added n new pages at the staring then total time complexity O(n^2 ).

- siva.sai.2020 March 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use ArrayList where any page can be accessed in o(1)and if you add randon pages the arraylist memeory increased dynamically

- deaGle(mahesh) March 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think LinkedList would be good, as we can add a page with the worst time of O(n), the insertion will be easy in ArrayList (or) tree but the followup (incrementing rest of the entities) will be painful.

- inasaa March 21, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How to reorder the pages in the Linked List if a page is inserted at nth position??, for ex:

1 2 3 4 5, add page 4 so 4 in the existing list changes to 5 and 5 to 6

- WittyWoman March 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if u think about it naturally. linkedlist is the way to go.

- Anonymous June 14, 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