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 challengesNim Showdown

Gamified challenge · Game trees

Nim Showdown

piles[i] is the number of stones in pile i. Two players alternate; on a turn the player picks one pile and takes between 1 and maxTake stones from it (never more than it holds). The player who takes the last stone wins; a player with no stones to take has lost.

It's your turn. Write winningMove(piles, maxTake) returning [pile, count] for a move after which you win however your rival plays, or [-1, -1] if every move loses against perfect play. Any winning move is accepted. For piles = [5], maxTake = 3: take 1, leaving 4; whatever your rival takes (1-3) you take the rest of the group of 4, so [0, 1].

A minimax search over the game tree works on small tables; remembering solved positions, or spotting the pattern, handles the big ones.

Sign in to play Nim Showdown

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