Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Set all odd bits
Basic Accuracy: 37.88% Submissions: 66 Points: 1

Given a number, the task is to set all odd bits of a number.
NOTE: Position of Least Significant Bit is considered as 1.

Example 1:

Input: n = 20
Output: 21
Explanation: Binary representation of 20
is 10100. Setting all odd bits make the
number 10101 which is binary
representation of 21.


Example 2:

Input: n = 10
Output: 15
Explanation: Binary representation of 10
is 1010. Setting all odd bits make the
number 1111 which is binary representation
of 15.

You dont need to read input or print anything. Complete the function setAllOddBitsâ€‹() which takes n as input parameter and returns the modified number.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1<= n <=109

to report an issue on this page.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?