FastPrepFastPrep
Problem Brief

First Unique Log Entry

FULLTIMEONSITE INTERVIEW
See Uber online assessment and hiring insights

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 Description

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.

1Example 1

Input
logs = ["A", "B", "A", "C", "B"]
Output
"C"
Explanation

A and B each appear twice. C is the first log whose total frequency is exactly one.

2Example 2

Input
logs = ["x", "y", "x", "y"]
Output
""
Explanation

Every log appears more than once, so there is no unique entry.

Constraints

Limits and guarantees your solution can rely on.

  • 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.
public String findFirstUniqueLog(String[] logs) {
    // write your code here
}
Input

logs

["A", "B", "A", "C", "B"]

Output

"C"

Sign in to submit your solution.