Here is the full interview question "First Unique Log Entry - Uber Coding Interview | ShowOffer" from Uber on ShowOffer.io:
Given a list of logs, each log is a string formatted as "Time: Log", where Time is in the format HH:MM:SS and Log is a string. You need to find the first unique log entry. A log entry is unique if it only appears once in the list of logs.
Input: logs = ["08:00:00", "01:01:01", "02:02:02", "01:01:01"] Output: "08:00:00"
Input: logs = ["01:01:01", "01:01:01", "02:02:02", "03:03:03", "02:02:02"] Output: "01:01:01"
0 <= logs.length <= 1000 <= len(logs[i]) <= 100logs[i] is in the format "HH:MM:SS Log"`python def firstUnique(logs): count = {} for log in logs: _, log = log.split(" ", 1) if log not in count: count[log] = 1 else: count[log] += 1
for log in logs:
_, log = log.split(" ", 1)
if count[log] == 1:
return log
return ""
print(firstUnique(["08:00:00", "01:01:01", "02:02:02", "01:01:01"])) # Output: "08:00:00" print(firstUnique(["01:01:01", "01:01:01", "02:02:02", "03:03:03", "02:02:02"])) # Output: "01:01:01" `
This solution uses a hash map to store the frequency of each log entry and then iterates through the logs to find the first unique log entry. The time complexity is O(n), where n is the number of logs.