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 challengesFractional Cargo

Gamified challenge · Greedy by ratio

Fractional Cargo

Each item is [weight, value] (weight in kg, at least 1). The hold carries at most cap kg. You may take any fraction of an item: x kg of it is worth value × x / weight.

Write maxValue(items, cap) that returns the largest total value that fits, as a decimal number. Answers within 1e-5 of the right value are accepted. For [[10, 60], [20, 100], [30, 120]] and cap = 50 the answer is 240.0: all of the first two and 20 kg of the third.

Sign in to play Fractional Cargo

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