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 challengesPower-of-Two Gates

Gamified challenge · Bit tricks

Power-of-Two Gates

A gate opens for n only if n is a power of two: 1, 2, 4, 8, …, i.e. n = 2^k for some k ≥ 0. n is any 32-bit signed integer, so it can be 0 or negative (those never open the gate).

Write isPower(n) (Python: is_power(n)) that returns true if the gate opens and false otherwise. 16 → true, 6 → false, 1 → true (it's 2^0).

A power of two has exactly one 1-bit. Can you test that without a loop?

Sign in to play Power-of-Two Gates

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