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 challengesStock Trader Days

Gamified challenge · State-machine DP

Stock Trader Days

prices[i] is the price of one share on day i. You may buy and sell as many times as you like, but you can hold at most one share at a time, and after you sell you must skip the next day (no buying on it). You may buy and sell only at that day's price, and you don't have to trade at all.

Write maxProfit(prices) (Python max_profit) that returns the largest total profit you can make. With no profitable trade the answer is 0.

Example: for [1, 2, 3, 0, 2] buy at 1, sell at 2, rest on day 2, buy at 0, sell at 2: the answer is 3.

Sign in to play Stock Trader Days

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