Interview Question for Analysts


Country: United States
Interview Type: In-Person




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

HeapSort

- ash.taunk3 June 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

HeapSort

- ashish June 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A priority queue is a max/min heap itself. If you insert all the elements into a priority queue and dequeue one by one, the output will automatically sorted. This way you just need one priority queue and O(nlogn) time complexity.

If we need to use two queues, then insert half of the array to each queue, then dequeue them following the "merge" method in merge sort. But I don't think it will be faster this way.

- hieu.pham June 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you have to solve with two queues, you will need a max and min Queue.
After inserting, you will need to exchange elements to keep both queues with the same number of elements as possible.

Use the mediam to determine where you should insert.

- Felipe Cerqueira June 20, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you please elaborate a little or give some psuedo code ?

- um01 June 21, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Another solution:
1. build a min PQ A
2. get the root node[1] from A, remember its index i and insert it to second min PQ B
3. delete the node[i] from B(the smallest one)
4. get two children of node[i] from A, remember their indexes and insert them to B
5. repeat 3-4 to get the half sorted array
6. sort down the remaining half items

- Dancy June 24, 2015 | 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