Flipkart Interview Question

flipkart logo
flipkart
SDE INo Offer
May 30, 202121 reads

Summary

I recently interviewed at Flipkart for an SDE1 role and was challenged to design a data structure for tracking the top K stocks from a real-time stream. Unfortunately, I was unable to provide a satisfactory solution.

Full Experience

I recently had an interview at Flipkart for an SDE1 position. During the technical round, I was presented with a design problem: to create a data structure capable of efficiently providing the top 10 stocks from a continuous stream of (id, stock-price) tuples at any given point in time. The interviewer explained that a function like getTop10() should return a list of the 10 stocks with the maximum current value. An example was provided: for a stream such as (a, 10), (b,20), (c,30), (d, 40), (a, 30), (d,10), a call to getTop2() should yield [{a,30}, (c,30)]. I attempted to implement a solution using a maxHeap, but the interviewer did not seem satisfied with my approach, and I felt I couldn't deliver a complete or optimal answer.

Interview Questions (1)

Q1
Design Data Structure for Top K Stocks in Stream
Data Structures & Algorithms

Design a data structure to give top 10 stocks from a stream of tuple at any point of time.
The tuple format is (id, stock-price).
Basically, getTop10() should be returning a list of top 10 stocks having maximum value at any point of time.

For example:
Stream -->>(a, 10), (b,20), (c,30), (d, 40), (a, 30), (d,10)

getTop2() returns [{a,30}, (c,30)];

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!