Problem
System Energy Reduction
Learn this problemProblem statement
You are given an integer n, where 0 < n < 2^60.
In one operation, you may add or subtract any power of two from n. That is, you may choose an integer k >= 0 and replace n with either n + 2^k or n - 2^k.
Return the minimum number of operations needed to reduce n to 0.
Function
minimumEnergyReductionOperations(n: long) → intExamples
Example 1
n = 7return = 2Add 1 to get 8, then subtract 8 to reach 0.
Example 2
n = 10return = 2Subtract 8, then subtract 2.
Constraints
0 < n < 2^60
More Salesforce problems
- Diameter of an Acyclic Undirected GraphONSITE INTERVIEW · Seen Jul 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- Maximum Barbell WeightOA · Seen Jul 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Jul 2026
- Minimum Operations to ZeroOA · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)OA · Seen Jun 2026