Rust Binary Gap
fn binary_gap(n: i64) -> i64 {
let bits = format!("{n:b}");
let trimmed = bits.trim_matches('0');
trimmed
.split('1')
.map(|zeroes| zeroes.len() as i64)
.max()
.unwrap_or(0)
}
This turns the number into binary, ignores zeroes outside the edges, and finds the longest run of zeroes between 1s.