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 challengesBit Counter Bulbs

Gamified challenge · Dynamic programming

Bit Counter Bulbs

A display shows a number in binary with bulbs: a lit bulb is a 1, a dark bulb a 0. It counts up from 0 to n.

Write countBits(n) (Python: count_bits(n)) that returns a list of n + 1 numbers, where item i is the number of lit bulbs (1-bits) of i. For n = 5 the answer is [0, 1, 1, 2, 1, 2] (0, 1, 10, 11, 100, 101).

Counting each number from scratch works; the neat answer reuses an earlier count, so each item takes O(1).

Sign in to play Bit Counter Bulbs

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