bugger.
All challenges/TypeScriptmediummicrosoft-sync-tombstones-v1
THE INVESTIGATION

The deleted file that comes back

An out-of-order file update resurrects a document after a newer deletion.

Microsoft-styleInterview practiceSynchronization

What’s going wrong

Original Microsoft-style interview practice. This is not an actual Microsoft interview question. Bugger does not provide an AI assistant.

A file-sync client removes a deleted file, but a delayed older upload brings it back. Repair synchronize so version checks continue to work after deletion.

Read {"events":[{"op":"put","path":"notes.txt","version":1,"content":"hello"},{"op":"delete","path":"notes.txt","version":2}]} from stdin. Process events in the supplied delivery order, starting with no files. Each path has an independent version history. Apply an event only if its version is strictly greater than every previously applied version for that path; ignore equal-version events, even if their operation or content differs. A delete records a deletion even for a path not yet seen. A later put with a strictly newer version restores the file.

Print an array of surviving files as {"path":string,"version":number,"content":string}, sorted by path in ascending ASCII order. Deleted files are absent from this output. Inputs are valid, contain at most 200 events, use nonempty ASCII paths, integer versions from 0 to 1000000, and string content for puts. Empty content is valid. No actual filesystem or network is used.

Expected behavior

Keep the newest version for every path, including deleted paths, so stale or duplicate deliveries cannot reverse a newer change.

Reproduction

01 A stale upload follows deletion
{"events":[{"op":"put","path":"notes.txt","version":1,"content":"old"},{"op":"delete","path":"notes.txt","version":3},{"op":"put","path":"notes.txt","version":2,"content":"late"}]}
[]
02 Ordinary newer upload control
{"events":[{"op":"put","path":"notes.txt","version":1,"content":"old"},{"op":"put","path":"notes.txt","version":2,"content":"new"}]}
[{"path":"notes.txt","version":2,"content":"new"}]
03 A newer upload deliberately restores a file
{"events":[{"op":"delete","path":"notes.txt","version":3},{"op":"put","path":"notes.txt","version":4,"content":"restored"}]}
[{"path":"notes.txt","version":4,"content":"restored"}]

Before you begin

  • TypeScript discriminated unions
  • Maps and ordered event processing
  • Distinguishing absent data from deletion metadata

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.