Uber | Phone Screen | L5-A role

Anonymous User
879
May 16, 2025
May 16, 2025

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

  1. incoming(num : int) -> This will ingest the number
  2. 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 :

  1. Keep a Set of seen integers and a variable minMissingNum
  2. 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 (2)