Problem. fruits[i] is the type of fruit on tree i. You have two baskets; each holds any amount of one
type. Start at any tree and pick one fruit from every tree moving right, stopping when a fruit fits neither basket.
Return the maximum number of fruits you can pick.
Stripped of the story: the length of the longest subarray with at most 2 distinct values.
[1, 2, 1] → 3
[0, 1, 2, 2] → 3 ([1, 2, 2])
[1, 2, 3, 2, 2] → 4 ([2, 3, 2, 2])
ML context. "The longest period with at most k distinct things" is a common log question: the longest stretch of traffic served by at most two model versions (a clean A/B window), the longest session touching at most k product categories, the longest run of a training log with at most k distinct warning types. Recognising the story as a window problem is half the interview.