Trees stand in a row, and fruits[i] is the type of fruit on tree i. You have two baskets, and each basket holds only one type of fruit (any number of pieces). Starting at any tree, you pick exactly one fruit from every tree to the right, in order, until you reach a tree whose fruit does not fit in the baskets, and then you stop. Return the most fruits you can pick.
This is the longest run of trees with at most two types. For [1, 2, 3, 2, 2] the answer is 4.
Example 1
Input:
total_fruit([1, 2, 3, 2, 2])
Output:
4
Example 2
Input:
total_fruit([0, 1, 2, 2])
Output:
3
0 <= len(fruits) <= 2000000 <= fruits[i] < 200000No results yet
Run your code to check it against the examples, or submit to run every test.