Content-Hash Deduplication

easy · content addressing

Deduplicate a list of text documents by the SHA-256 hash of their UTF-8 bytes. Return {'unique': texts in first-appearance order, 'indices': for each input text its index in unique}. Identical text is duplicate; do not normalize whitespace, case, or Unicode. Use hashlib.sha256, available in Python's standard library, and no external storage or network. Treat digest collisions as outside this exercise's domain. Examples (JSON; null means Python None): Input: {"texts": ["a", "b", "a"]} Output: {"unique": ["a", "b"], "indices": [0, 1, 0]} Input: {"texts": ["", " ", ""]} Output: {"unique": ["", " "], "indices": [0, 1, 0]}

Starter code

def deduplicate_content(texts: list[str]) -> dict:
    """Map content hashes to stable first-appearance indices."""
    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.