Highest Power of Two
Return the largest power of 2 that is less than or equal to n.
Example 1
n 10
returns 8
8 <= 10 < 16.
Example 2
n 16
returns 16
16 itself.
Constraints
1 <= n <= 10**6
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Is PrimeBeginner
- Lattice Points in a CircleBeginner
- Leap YearBeginner
- Matches in a TournamentBeginner
- Number of Common FactorsBeginner
- Power of FourBeginner
- Power of ThreeBeginner
- Power of TwoBeginner