Math Fundamentals18 sections · 814 units
Open in Course

Problem - Power of Two

(Check if number is power)

Given an integer n, return true if it is a power of two. Otherwise return false. An integer n is a power of two if there exists an integer x such that n = 2^x.

Examples: n = 1 → true (2^0). n = 16 → true (2^4). n = 3 → false.

This problem uses mod to check divisibility. Try thinking about it before reading on.