Section 1Understand Problem
Section 01
Understand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
Problem statement
You are visiting a farm with rows of fruit trees, and the i-th tree produces fruit of type `fruits[i]`. You start with two baskets and each basket can only carry one type of fruit. There is no limit on the amount of fruit per basket. You must pick exactly one fruit from every tree (including the start tree) while you walk to the right; you may not skip a tree, and you must stop once you reach a tree whose fruit doesn't fit in either basket. Return the maximum number of fruits you can pick.
Example
fruits = [1, 2, 1] → 3
Constraints
1 ≤ fruits.length ≤ 10⁵ · 0 ≤ fruits[i] < fruits.length
Audio recording unsupported on this browser.
WPM—Fillers0Pace—Thinking0%
Explain the problem in your own words
0 words0 chars
AI Review
Write your thinking above first.
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.
Ready to submit Section 1?
The reviewer will check whether you stated inputs, output, guarantees, and any assumption you flagged.
Write at least a couple of sentences explaining the problem before submitting.