Yahoo Interview Question for Software Development Managers


Country: United States
Interview Type: Phone Interview




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

The first idea is maintaining a min-heap of size 5 at any ticker. I will update this post if I have a better solution.

- Jason November 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Min-Heap = great solution!
Max-Heap = LOLZ.

- Anonymous November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

My solution was to maintain a max-heap and a map that maps ticker to the corresponding node in the heap. At every update, we look-up the node and update the value, but also note if it is an increase or decrease in value. If increase, we do a sift-up, if decrease, we do a sift-down on the heap for that node. For giving the top five values at any point of time, we don't want to disturb the order in the heap so we would copy the top five levels to a different memory and then perform 5 extract and heapifies on it.

- nosyDeveloper November 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I do not think max-heap is a good idea if you wanna delete the minimal one.

- Jason November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't think we need to often delete the tickers. And even if we need to, we can always update the value of stock to 0 to push it down.

- nosyDeveloper November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

But you think the operations if we would use a min-heap. I believe that a max-heap can finish the task.

- Jason November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry did not understand what u meant by "finish the task". We do want the task to be finished, don't we?

- nosyDeveloper November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry, I mean using a max-heap can display the top 5 stock prices at any given point of time. But a min-heap may be better considering the time complexity.

- Jason November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How do u plan to find top-5 elements with min-heap?

- nosyDeveloper November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

if the number of elements in the heap is smaller than 5, push the new element and update the heap. Otherwise, compare the new element (say n) with the first element (say m) in heap, if n<m, discard n, otherwise, replace m with n and adjust the heap.

- Jason November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

What if you have a stock value in top-5, say MSFT and the value goes down. You need to check if there is a new contender for the top-5 spot among all those other tickers that were discarded while building the heap last time. One way is to build it all over again - O(n). Expensive, isn't it?

- nosyDeveloper November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I suggest we keep a heap for each time ticker. While the problem is memory complexity. So in my another post, I suggest some possible solution to handle memory problem.

- Jason November 22, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am still confused which one to choose between min-heap and max-heap. Please throw some light on this issue. Brief description with an example would be highly appreciated.

- Akshay Kulkarni February 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about a max heap of size 5. One of the last two elements in the Heap Array(List) is the smallest. Therefore,

1) lastElem = list.get(list.length()-1))
2) lastButOneElem =  list.get(list.length()-2))
3) int smallestIndex = lastElem .compareTo(lastButOneElem) > 0 ? list.length()-2 : list.length()-1
4) list.set(smallestIndex , newElemFromStream)
5) heapUp(smallestIndex)

- Aditya June 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeah, but if it's a minheap, than it's guaranteed that the root node will be the minimum, so you can just compare it against that node. Than, if the new element is greater in value than the root node, than we delete the root node, which will take O(log n), and we insert the new node O(log n); here n is 1 since it's a root node, so it's relatively easy.

- iamseiko September 12, 2014 | 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