Loading Now

maxBits

Given an integer n, find the largest positive integer that has the same number of 0s and 1s in its binary representation.

Example

  • For n = 5, the output should be maxBits(n) = 6.

    5 = 1012, so the answer is 1102 = 6.

  • For n = 15, the output should be maxBits(n) = 15.

    15 = 11112, so the answer is 11112 = 15.

Input/Output

  • [execution time limit] 0.5 seconds

  • [input] integer n

    Constraints:

    0 ≤ n ≤ 1000

  • [output] integer

    • An integer that has as many 0s and 1s as n

Post Comment

Contact