GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesFruit Basket Run

Gamified challenge · Sliding window

Fruit Basket Run

trees[i] is the type of fruit on tree i in an orchard row. You carry two baskets, and each basket holds only one type of fruit (as much of it as you like). Start at any tree and walk right, picking exactly one fruit from every tree you pass. You must stop at the first tree whose fruit fits in neither basket.

Write totalFruit(trees) (total_fruit in Python) that returns the most fruit you can pick: the length of the longest run of consecutive trees with at most two fruit types. An empty row gives 0.

For [3, 3, 3, 1, 2, 1, 1, 2, 3, 3, 4] the best run is [1, 2, 1, 1, 2]: 5 fruit.

Sign in to play Fruit Basket Run

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account