Tap here to switch tabs
Problem
Submissions

Problem: Binary Gap

med
30 min
Try to solve the Binary Gap problem.

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

med
30 min
Try to solve the Binary Gap problem.

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