Coding questions · Uber
Maintain the First Value That Appears Exactly Once
Practice a Uber coding interview problem focused on maintain the first value that appears exactly once. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.
Design a data structure that maintains a stream of integers and returns the first value that appears exactly once.
Implement:
class FirstUniqueValue:
def __init__(self, nums: list[int]): pass
def show_first_unique(self) -> int: pass
def add(self, value: int) -> None: pass
Return -1 if no value is unique.
First Unique Value in a Stream
Simulate a stream supporting add and show_first_unique operations.
Examples
Example 1
Input: {"initial":[2,3,5],"operations":[["show"],["add",5],["show"],["add",2],["show"],["add",3],["show"]]}
Output: [2,2,3,-1]
Explanation: Classic stream.
Example 2
Input: {"initial":[],"operations":[["show"]]}
Output: [-1]
Explanation: Empty.