Log Deduplication

Asked at Google

Reported by the problem's creator, not verified

A log collector receives entries. Each entry is a timestamp (an integer) and a message (a string). Entries arrive in an order that has nothing to do with their timestamps. LogDeduper() starts empty, and add(timestamp, message) hands it one entry. The collector keeps at most one entry per message.

Wherever entries are listed, they are [timestamp, message] lists ordered by timestamp, with equal timestamps ordered by message as ordinary strings.

Examples

  1. Example 1

    Input: init = [], operations = [["retained",[]],["add",[5,"disk full"]],["add",[3,"timeout"]],["add",[9,"disk full"]],["add",[1,"disk full"]],["add",[3,"boot"]],["retained",[]]]

    Output: [[],null,null,null,null,null,[[3,"boot"],[3,"timeout"],[5,"disk full"]]]

    Explanation: disk full first arrives with timestamp 5, so the later entries with timestamps 9 and 1 are dropped. boot and timeout both have timestamp 3 and are ordered by message.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.