PythonStudio
Interview Problems

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 compiler