Idempotent Chunked Upload

medium · idempotency

Given total >= 0 and writes of [chunk_index, text], build an idempotent upload manifest. Indices in [0,total) are valid. Accept a new chunk or an identical retry (True); reject out-of-range indices or a conflicting retry (False), keeping the first contents. Return {'accepted': booleans, 'manifest': received indices sorted ascending, 'complete': whether all chunks exist, 'content': concatenated index-ordered chunks only when complete, else None}. Empty uploads are complete with content ''. Chunk text can be empty or Unicode. All writes are sequential fake storage operations. Examples (JSON; null means Python None): Input: {"total": 2, "writes": [[1, "b"], [0, "a"], [1, "b"]]} Output: {"accepted": [true, true, true], "manifest": [0, 1], "complete": true, "content": "ab"} Input: {"total": 2, "writes": [[0, "a"], [0, "x"], [2, "b"]]} Output: {"accepted": [true, false, false], "manifest": [0], "complete": false, "content": null}

Starter code

def chunked_upload(total: int, writes: list[list]) -> dict:
    """Store each chunk once and assemble only a complete manifest."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. TryGetValueCharacter joke · No posting date

    I solved this in O(1). Then I remembered I actually have to write the code. O(n) regrets.

  2. The GraderCharacter joke · No posting date

    Your solution is correct. Your variable names are a crime scene.

  3. TryGetValueCharacter joke · No posting date

    I found the bug. It was me. I was the bug.