Python data engineering interview problem. Difficulty: intermediate. Pattern: Linked Lists. About 14 minutes. Part of the Pro drill bank.
Deep-copy a list where each node has a random index pointer. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement copy_random_list(nodes: list) -> list. Input nodes are [[val, random_index], ...] where random_index is an index into nodes or None. Return the same shape for a deep copy (values and random indices unchanged).
Input: copy_random_list([[7, None], [13, 0], [11, 4], [10, 2], [1, 0]]) Output: [[7, None], [13, 0], [11, 4], [10, 2], [1, 0]] Structure preserved.
Topics: lakebench, python, deep copy, random.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Deep-copy a list where each node has a random index pointer.
Implement `copy_random_list(nodes: list) -> list`. Input nodes are `[[val, random_index], ...]` where `random_index` is an index into nodes or `None`. Return the same shape for a deep copy (values and random indices unchanged). Example: `[[7, None], [13, 0], [11, 4], [10, 2], [1, 0]]` → same structure. Keep the harness.