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 challengesCurrency Loop Detector

Gamified challenge · Bellman-Ford

Currency Loop Detector

There are n currencies, 0 to n - 1. Each entry [from, to, cost] of trades is a one-way exchange desk. Real rates multiply, so they have been turned into integer costs that add up: cost = round(-100 · ln(rate)). A positive cost loses money, a negative cost gains.

A free-money loop is a sequence of trades that starts and ends in the same currency with a negative total cost. Write hasArbitrage(n, trades) that returns true if any such loop exists anywhere in the market, else false. A loop totalling exactly 0 only breaks even.

Example: [[0,1,-10],[1,2,-5],[2,0,12]] with n = 3 has the loop 0 → 1 → 2 → 0 totalling -3, so the answer is true.

Sign in to play Currency Loop Detector

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