Daily challenge for 2026-11-13
682. Document Revision Snapshot
You are given a list of document operations representing edits to a document. Each operation is either a string (which means append that string to the document) or an integer k (which means undo the last k append operations). Return the final document as a single string.
Assumptions:
- The input ops is a list where elements are either strings or non-negative integers.
- If an undo operation requests to undo more appends than are currently in the document, undo all of them (clear the document).
- Undo operations only undo appends, not other undos.
Example:Input: ops = ["hello", " ", "world", 1, "leet"]Output: "hello leet"
Constraints: There are 0 to 2000 operations. Append values are ASCII strings, including empty strings, with a combined length at most 20000. Undo values are integers from 0 through 2000. An empty operation list returns an empty string.