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 challengesFuel Loop

Gamified challenge · Greedy elimination

Fuel Loop

Stations 0 to n − 1 sit on a ring road. At station i the car can fill up gas[i] fuel, and driving on to station i + 1 (station 0 after the last) burns cost[i]. The tank starts empty and has no limit; it must never go below zero.

Write startStation(gas, cost) that returns a station from which the car can drive once all the way round, or -1 if there is none. If several stations work, any of them is accepted.

For gas = [1, 2, 3, 4, 5], cost = [3, 4, 5, 1, 2] the answer is 3: the tank reads 3, 6, 4, 2, 0 after each leg.

Sign in to play Fuel Loop

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