Stream Unique Logs in Timestamp Order
Updated
Problem statement
Process a finite sequence of log-stream operations from left to right. Each log is a pair containing an integer timestamp and a message.
- For an
addoperation, accept the supplied log only if its message has never been accepted earlier in the sequence. A message remains accepted for uniqueness purposes even after its log is returned. Otherwise, ignore the log. - For a
getoperation, remove and return the currently pending accepted log with the smallest timestamp. If multiple pending logs have the same timestamp, return the one whose message is lexicographically smaller. If no log is pending, returnEMPTY.
Only add operations already processed are available to a get. A later operation never changes a result that was already returned.
Return one string for each get, in operation order. Encode a returned log as timestamp|message. The timestamp and message entries at a get position are placeholders and are ignored.
Function
processUniqueLogs(operations: String[], timestamps: int[], messages: String[]) → String[]Examples
Example 1
operations = ["add","add","get","add","get","get"]timestamps = [5,3,0,1,0,0]messages = ["alpha","beta","","alpha","",""]return = ["3|beta","5|alpha","EMPTY"]The first get returns 3|beta. The second alpha log is rejected because that message was already accepted, so the next result is 5|alpha. The final get finds no pending log.
Example 2
operations = ["add","add","get","get"]timestamps = [7,7,0,0]messages = ["zeta","alpha","",""]return = ["7|alpha","7|zeta"]Both logs have timestamp 7, so the lexicographically smaller message alpha is returned first.
Example 3
operations = ["add","get","add","get"]timestamps = [10,0,1,0]messages = ["late","","early",""]return = ["10|late","1|early"]The first get can see only the first log. The later log has a smaller timestamp, but it does not revise the earlier result.
Constraints
1 <= operations.length <= 10^5.operations.length == timestamps.length == messages.length.- Every operation is either
addorget. - At an
addposition,0 <= timestamps[i] <= 10^9. - At an
addposition,messages[i]contains between1and20lowercase English letters. - At a
getposition,timestamps[i]andmessages[i]are ignored.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
- Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Execute Tasks by PrioritySnowflake · ONSITE INTERVIEWSnowflake interview questions
- Worker Assignment — Skills and Account AffinityStripe · ONSITE INTERVIEWStripe interview questions
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Scheduled Payments with Account AliasesCoinbase · ONSITE INTERVIEWCoinbase interview questions
- Keyed Bounded Executor ScheduleMicrosoft · ONSITE INTERVIEWMicrosoft interview questions