Skip to content

9. Find the Missing IDs

Difficulty: Easy · Topic: Core Python & data structures

A source system says which order ids it sent; the warehouse lists the ids it received. Write missing_ids(expected, received): return the ids that are in expected but not in received, sorted in ascending order, each id once.

Example: missing_ids([1, 2, 3, 4], [2, 4]) gives [1, 3].

Your code runs in CPython on our servers against 7 tests, including hidden ones.

Sample test

missing_ids([1, 2, 3, 4], [2, 4])

Expected: [1, 3]

Hints

Hint 1A set answers "is this id in there?" in O(1), and duplicates disappear.
Hint 2The - operator on two sets keeps what is only in the first one. Sets have no order, so sort the result.

Learn the concepts

More Python problems

All Python problems