Beats 100% solution. Super easy cpp code.
IntuitionFind the nearest power (p) of 2 which surpasses n. Subtract 1 from the number (p-1);ApproachInitialize count=0;
Run a while loop and divide the number
# Intuition
Find the nearest power (p) of 2 which surpasses n. Subtract 1 from the number (p-1);

# Approach
Initialize count=0;
Run a while loop and divide the number by 2 till n becomes 0 and count++;

# Complexity
- Time complexity:
O(n).
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
public:
    int smallestNumber(int n) {
        int cnt=0;
        while(n)
        {
            n/=2;
            cnt++;
        }
        return (1<<cnt)-1;
    }
};
```
['C++']