Back to problems

Maintain the First Value That Appears Exactly Once

Algorithm · Uber · Medium

Design a data structure that processes a sequence of integers as it grows. It must support queries for the earliest inserted value whose current occurrence count is exactly one. If several values have occurred once, return the one that entered the stream first; if no value qualifies, return -1. Implement the following API: The constructor receives an initial list of integers nums. These values should be counted immediately in the order they appear. Each call to add appends…

Checking your access…