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 challengesCandy Line

Gamified challenge · Two-pass greedy

Candy Line

Children stand in a line; ratings[i] is child i's rating. Every child gets at least one candy, and a child with a higher rating than a neighbour must get more candy than that neighbour. Equal ratings carry no rule.

Write minCandy(ratings) that returns the fewest candies in total that satisfy both rules. For [1, 0, 2] the answer is 5 (give 2, 1, 2); for [1, 2, 2] it is 4 (give 1, 2, 1).

Sign in to play Candy Line

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