Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can we set/unset the bits in binary representation?
If there are multiple adjacent ones, how can we optimally add and subtract in 2 operations such that all ones get unset?
Bonus: Try to solve the problem with higher constraints: n ≤ 10^18.