Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Fruit Into Baskets

A row of trees has fruit types given by an array. You have two baskets, each holding one type of fruit without limit. Starting at any tree you pick one fruit from each tree moving right and must stop when a tree's fruit does not fit. Print the maximum number of fruits you can collect.

Constraints

1 <= n <= 10^5 0 <= type < n

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.