Bit Updation 🔥✅ - Beats 100% | C++ Solution
IntuitionStart with the value 1. Now we will keep converting our number from 1 -> 11 -> 111 like this , until it become just greater than the n.Approachwhile th
# Intuition
Start with the value 1. Now we will keep converting our number from 1 -> 11 -> 111 like this , until it become just greater than the n.

# Approach

while the value of x is lesser than n we will convert right most unset bit to 1. 

Simply run a while loop until the value of x is lesser than n. In each iteration left shift the x and take OR with 1 , to set the last bit. 
x = x<<1 | 1;
This will give the required answer;

# Complexity
- Time complexity:
$$O(logn)$$ -->

- Space complexity:
$$O(1)$$

# Code
```cpp []
class Solution {
public:
    int smallestNumber(int n) {
        int x = 1; 
        while(x<n){
            x = x << 1 | 1;
        }
        return x;
    }
};
```
['C++']