Tap here to switch tabs
Problem
Submissions

Problem: Binary Gap

Binary Gap asks you to find the greatest distance between adjacent one bits in an integer's binary representation, returning zero when it contains fewer than two one bits.

Statement

Given an integer n, return the maximum distance between two adjacent 1 bits in the binary representation of n.

The distance between two adjacent 1 bits is the number of positions between them in the binary string.

If there are fewer than two 1 bits in the binary representation of n, return 0.

Note: The binary representation does not include leading zeros.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Binary Gap

Binary Gap asks you to find the greatest distance between adjacent one bits in an integer's binary representation, returning zero when it contains fewer than two one bits.

Statement

Given an integer n, return the maximum distance between two adjacent 1 bits in the binary representation of n.

The distance between two adjacent 1 bits is the number of positions between them in the binary string.

If there are fewer than two 1 bits in the binary representation of n, return 0.

Note: The binary representation does not include leading zeros.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9