FunctionRacerProblemsRace

Power of Two

BeginnerMathPython, JavaScript, TypeScript, Java, C++

Return True if n can be written as 2 raised to some whole number power (1, 2, 4, 8, ...), otherwise False. Zero and negative numbers are not powers of two.

Example 1

n 16
returns true

2 to the 4th.

Example 2

n 12
returns false

Not a power of two.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems