Lessons 16–20 · About 60 min per lesson
Sorting, frequencies and missing values
Turn repeats and gaps into counts you can verify.
Lesson breakdown
- Lesson 16
Check adjacent values for repeats after sorting.
- Lesson 17
Build a frequency table and explain its key-range requirements.
- Lesson 18
Count sparse values with a map and query absent keys.
- Lesson 19
Find the smallest missing nonnegative integer by scanning from 0.
- Lesson 20
Check repeated records, consecutive values and a missing 0.
Worked example
Find the smallest missing nonnegative integer in [0,2,2,1,4].
How to solve it
0, 1 and 2 are present, and 3 is the first missing value. The duplicate 2 does not change the result.
Assignment
Read a list of nonnegative integers and print the first gap and the number of distinct values that appear more than once.
Check your result
The example gives 3 1; [2,2,5,5] → 0 2; an empty list → 0 0.