Problem · Hash Table

First Unique Log Entry

Learn this problem
EasyUber logoUberFULLTIMEONSITE INTERVIEW
See Uber hiring insights

Problem 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[]) → String

Complete the function findFirstUniqueLog in the editor below.

findFirstUniqueLog has the following parameter:

  1. 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.

More Uber problems

drafts saved locally
public String findFirstUniqueLog(String[] logs) {
    // write your code here
}
logs["A", "B", "A", "C", "B"]
expected"C"
checking account