Problem · Hash Table
First Unique Log Entry
Learn this problemProblem statement
You are given process logs in arrival order. Treat each log as a full string entry.
Return the first log entry that appears exactly once in the entire sequence. If no such log exists, return an empty string.
Function
findFirstUniqueLog(logs: String[]) → StringComplete the function findFirstUniqueLog in the editor below.
findFirstUniqueLog has the following parameter:
String[] logs: the process logs in arrival order
Returns
String: the first log whose final frequency is exactly one, or "" if none exists.
Examples
Example 1
logs = ["A", "B", "A", "C", "B"]return = "C"A and B each appear twice. C is the first log whose total frequency is exactly one.
Example 2
logs = ["x", "y", "x", "y"]return = ""Every log appears more than once, so there is no unique entry.
Constraints
1 <= logs.length <= 10^6- Each log entry is treated as an entire string and may contain spaces.
- The answer is based on the original order among log entries whose final count is exactly one.