FastPrepFastPrep
Problem Brief

Minimum Operations to Make Binary Palindromic

INTERNOA
See Google online assessment and hiring insights

You are given a number N (0<=N<=2*1e9) and you can do the following operation any number of times including zero. In one operation you can increase or decrease the number by 1. Your task is to find the minimum number of operations to make the binary form of the N palindromic.

1Example 1

Input
N = 6
Output
1
Explanation

You need to decrease N by 1 to make it 5 as binary representation of 5 is Palindromic (101) or you can increase N by 1 to make it 7 as its binary is also palindromic (111).

Constraints

Limits and guarantees your solution can rely on.

0 <= N <= 2 * 109
public int minOperationsToMakeBinaryPalindromic(int N) {
  // write your code here
}
Input

N

6

Output

1

Sign in to submit your solution.