Uber | Phone Screen | L5-A role

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-05-16Added By Anonymous
Source: Link

Original Post Content:


There is a stream of numbers incoming. They can come in any order. We have to implement two methods.


incoming(num : int) -> This will ingest the number

getMissingMinSoFar() : -> This will return minimum missing number from the stream

Example

stream.getMissingMinSoFar() -> 0

stream.incoming(0)

stream.incoming(1)

stream.getMissingMinSoFar() -> 2


stream.incoming(5)

stream.getMissingMinSoFar() -> 2

stream.incoming(2)

stream.getMissingMinSoFar() -> 3


Solution :


Keep a Set of seen integers and a variable minMissingNum

When you have an incoming number , check if it is equal to minMissingNum , if no add it to the seen set

if yes, check if it is equal to minSoFar , if yes increment minSoFar until you find it in set


Comments