Minimum Operations to Reduce an Integer to 0
Medium · Bit Manipulation · about 20 minutes
Asked at Salesforce, Uber, Microsoft, NVIDIA, Bloomberg, Hudson River Trading, Optiver, Epic Games, Jump Trading.
n is a positive integer. One move adds any power of 2 to it or subtracts any power of 2 from it. What is the fewest moves that bring it to exactly 0?