100% Best Solution
IntuitionAll set bits are present in numbers just before the powers of 2 for example 7 just before 8 , 15 just before 16 etc. So we will count the number of bit
# Intuition
All set bits are present in numbers just before the powers of 2 for example 7 just before 8 , 15 just before 16 etc. So we will count the number of bits in the number n(given) and return 2 to the power the number of bits in that number - 1. 

# Approach
Initialize count variable and count the number of bits with the help of a while loop and right shifting or dividing number by 2.

# Complexity
- Time complexity:O(logN)

- Space complexity:O(1)

# Code
```cpp []
class Solution {
public:
    int smallestNumber(int n) {
        int num = n , cnt = 0;
        while(num){
            num = num >> 1;
            cnt++;
        }
        return pow(2,cnt) - 1;
    }
};
```
['C++']