Dsa
Bit Manipulation
Medium
Next Greater Power of Two
For a given positive integer n, find the next greater power of two. If n is already a power of two, return n itself.
For example:
Input:
6
Output:
8
Explanation:
The powers of two are 1, 2, 4, 8, ... The next greater power of two after 6 is 8.
Key concepts
bit manipulationpowers of two
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now