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 challengesSubarray Vault

Gamified challenge · Prefix sums

Subarray Vault

deposits[i] is the net amount that moved on day i: positive for deposits, negative for withdrawals, 0 for a quiet day. A stretch is one or more consecutive days. Write countK(deposits, k) that returns how many stretches have a total of exactly k.

For deposits = [1, 2, 3] and k = 3 the answer is 2: the stretches [1, 2] and [3]. Different stretches count separately even if their days hold the same values, so [0, 0, 0, 0] with k = 0 has 10.

Because withdrawals can make the total go down, a sliding window doesn't work here; think about running totals.

Sign in to play Subarray Vault

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