You walk along a row of trees; fruits[i] is the fruit type of the i-th tree. You have two baskets, each holding only one type. Starting anywhere, you pick one fruit per tree moving right, stopping when a tree's fruit fits neither basket. Return the maximum number of fruits you can collect — i.e. the longest subarray with at most two distinct values.
Input: one line of space-separated integers fruits.
Output: the maximum number of fruits.
1 2 1
3
0 1 2 2
3
[1,2,2] uses two types.
1 2 3 2 2
4
[2,3,2,2].
Run your code against the sample tests, or Submit to run the full suite.