Find Disappeared
Python data engineering interview problem. Difficulty: beginner. Pattern: Arrays. About 10 minutes. Free to practice.
Find all numbers in 1..n missing from the array. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
A numbered batch should contain every id from 1 to n, but duplicate rows can hide ids that never arrived. Return all numbers in 1 to n that do not appear in the input. The list has length n and may repeat values. The missing values must be sorted from smallest to largest. Write the function find_disappeared(nums: list) -> list. The sample has length 8. It includes 1, 2, 3, 4, 7 and 8, so 5 and 6 are missing and the answer is [5, 6]. The starter file already has the function name and the harness print lines. Keep them, and fill only the function body.
Requirements
- Check the complete range from 1 through the list length.
- Do not report a value just because it appears more than once.
- Return missing numbers in ascending order.
Constraints
- nums has length n and every value is between 1 and n.
- The return type is a list, and the list may contain duplicates.
Examples
Input: find_disappeared([4, 3, 2, 7, 8, 2, 3, 1]) Output: [5, 6] 5 and 6 never appear.
Topics: lakebench, python, missing, range.
More Python interview questions · All interview problems · Learn data engineering
Find Disappeared
Interview-style drill: Find all numbers in 1..n missing from the array.
Implement `find_disappeared(nums: list) -> list` for nums of length n with values in 1..n. Return missing numbers sorted. Example: `[4, 3, 2, 7, 8, 2, 3, 1]` → `[5, 6]`. Keep the harness.