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
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 fullfirst arrives with timestamp 5, so the later entries with timestamps 9 and 1 are dropped.bootandtimeoutboth have timestamp 3 and are ordered by message.