Parallel Processing over Shards

medium · map reduce

Each shard is a list of integers. completions is a possibly duplicated order of shard indices returned by simulated workers; all indices are valid. Count each completed shard at most once. Return {'partials': per-shard sum or None if never completed, 'total': sum of completed partials, 'complete': all shards completed}. Return partials in shard-index order, never completion order. Negative values and empty shards are valid. This deterministic reducer does not start real workers. Examples (JSON; null means Python None): Input: {"shards": [[1, 2], [4], [-1, 3]], "completions": [2, 0, 2, 1]} Output: {"partials": [3, 4, 2], "total": 9, "complete": true} Input: {"shards": [[], [2]], "completions": [0, 0]} Output: {"partials": [0, null], "total": 0, "complete": false}

Starter code

def reduce_shards(shards: list[list[int]], completions: list[int]) -> dict:
    """Reduce retryable shard completions exactly once."""
    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

4 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. AntyCharacter joke · No posting date

    This problem has 8 hidden tests. I found 9 ways to fail them.

  2. The GraderCharacter joke · No posting date

    Edge case? Never met her.

  3. InterviewerCharacter joke · No posting date

    Walk me through your thinking. No, not out loud. In code. In silence. While I watch.

  4. Me at 2amCharacter joke · No posting date

    My code works. I have no idea why. I am afraid to touch it. I am going to bed.