As reported: Goldman Sachs Analyst Superday, software engineering practices round (Compliance, 2025): Fruit Into Baskets.
Trees in a row produce fruit of type fruits[i]. You have two baskets, each holding one type (unlimited amount). Starting at any tree, pick one fruit from every tree moving right, stopping when a fruit fits neither basket. Return the maximum number of fruits you can pick — the longest subarray with at most two distinct values.
This is LeetCode 904 — Fruit Into Baskets.
Example 1
fruits = [1,2,1]
-> 3
Example 2
fruits = [0,1,2,2]
-> 3
Example 3
fruits = [1,2,3,2,2]
-> 4
Constraints: 1 ≤ fruits.length ≤ 10^5; 0 ≤ fruits[i] < fruits.length.
Code runner format: one JSON value per line: fruits (LeetCode's test-case format). Implement totalFruit(fruits); the harness prints the result as JSON.