[Oracle technical discussion]Sorting stream of integer Design a lib/api[2yrs exp.]
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-08-12Added By Anonymous
Source: Link
Company: Oracle
Role: ic-1
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Recently I appeared for an interview and a question was asked in this way:
You are receiving a stream of integers at very high speed. The client has 2 requirements:
1.To get the list of integers in the order being consumed.
2.You should be able to return a sorted list of integers when the client asks for a sorted list.
The required APIs are:
1.int[] getListofInteger()
2.int[] getSortedListofInteger()
How would you design this? Which data structure would you use to design this requirement? Can you do better than sorting an array list every time you get a request, i.e., can we do it without a heavy operation or sorting in O(n log n)?
Any knowledge share or insights to tackle these kinds of questions would help me. Thanks in advance.