Toy Shelf
Challenge on lesson: Checkpoint — Two Pointers
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** A shelf holds n toys in a row; toy i has type t[i] (1..100). Choose
one contiguous segment containing at most k DISTINCT types, maximizing the number
of toys taken.
**Input:** Line 1: n k (1 <= n <= 200000, 1 <= k <= 100). Line 2: n integers
(1 <= t[i] <= 100).
**Output:** One integer — the maximum segment length.
**Example:** 6 2 / 1 2 1 3 4 3 -> 3 (1 2 1 and 3 4 3 are the best
2-distinct segments).
Press Submit to check your solution.
Back to lesson: Checkpoint — Two Pointers