Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Power of Two

Easy
bit-manipulationmath

Return true if integer n is a power of two (n = 2ᵏ for some k ≥ 0). No loops or recursion needed.

Input: one line, the integer n (may be negative). Output: true or false.

Example 1
Input:
1
Output:
true

2⁰.

Example 2
Input:
16
Output:
true
Example 3
Input:
3
Output:
false

Constraints

  • -2^31 ≤ n ≤ 2^31 − 1
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.