A note-taking app has several documents open in tabs, and each document is debounced on its own: an edit to a document cancels that document's pending save and schedules a new one wait ms later. Edits to one document never affect another.
edits is a list of [time, docId] pairs sorted by time. A save due at exactly the time of an edit to the same document happens before that edit. Write autosaves(edits, wait) that returns all saves as [time, docId] pairs, sorted by time and then by docId (character-code order).
Input: edits = [[0,"a"],[100,"b"],[150,"a"],[900,"b"]], wait = 500 Output: [[600,"b"],[650,"a"],[1400,"b"]]
a is edited at 0 and 150, so it saves at 650. b saves at 600, then again at 1400.
Input: edits = [[0,"x"],[0,"y"]], wait = 10 Output: [[10,"x"],[10,"y"]]
Two saves at the same time are ordered by docId.
0 <= edits.length <= 10^50 to 10^9, sorted ascending; docIds are non-empty strings.1 <= wait <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #723 Autosave Each Document Separately. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.