← Microsoft questions

Next smallest and largest numbers with same number of set bits

Filed under Microsoft

Given a positive integer, find the immediately smaller and immediately larger integers that have the exact same number of set bits (1s) in their binary representation.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Microsoft questions

Collected from public candidate posts and coding forums. Updated Nov 2026.