Find the First Unique IP
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency with streaming data handling, stateful data structures, and algorithmic design for identifying unique elements in chronological event streams, and is categorized under Coding & Algorithms.
Constraints
- 0 <= len(operations) == len(values) <= 200000
- Each operation is either "recordHit" or "getFirstUniqueIp"
- For "recordHit", the IP string length is between 1 and 45 characters
- The expected solution should run in O(n) total time across all operations
Examples
Input: (["recordHit", "recordHit", "recordHit", "getFirstUniqueIp", "recordHit", "getFirstUniqueIp", "recordHit", "getFirstUniqueIp"], ["10.0.0.1", "10.0.0.2", "10.0.0.1", None, "10.0.0.2", None, "10.0.0.3", None])
Expected Output: ["10.0.0.2", None, "10.0.0.3"]
Explanation: After the first three hits, only 10.0.0.2 is unique. After 10.0.0.2 appears again, no unique IP remains. After 10.0.0.3 is added, it becomes the first unique IP.
Input: ([], [])
Expected Output: []
Explanation: No operations means there are no query results.
Hints
- A hash map can track how many times each IP has appeared.
- You also need to preserve the order of candidate unique IPs. Consider a queue/deque with lazy cleanup from the front.