THE CHALLENGESMALLEST_RANGE — The smallest covering range.
You are given k sorted lists. Find the smallest range [min, max] that contains at least one element from each list. Print min, then max.
Input:
- line 1: k
- then k lines, each: the size of the list followed by its elements
Output:
two integers separated by a space: the min and max of the smallest range.
Example:
3
5 4 10 15 24 26
5 0 9 12 20
5 5 18 22 30
gives
20 24
How to break it down:
1. plus_petite_plage(listes): gathers every element as (value, list index) pairs.
2. Sorts these pairs by value and uses two pointers to cover every list.
3. Keeps track of the smallest spread (max - min) and prints its bounds.
Final challenge: sort all the (value, list number) pairs ONCE, then a sliding window with two pointers - no brute force, no import.
Checks (verified automatically before your code runs):
- At least 1 function definition.
- At least 1 call to plus_petite_plage().
- At least 1 call to sorted().
- Loops may be nested at most 2 levels deep.
- Not allowed: imports.
Hint: move the right end of the window until every list is covered, then shrink from the left as long as you can, keeping the smallest range.