FastPrepSystem Energy Reduction
Problems/System Energy Reduction

System Energy Reduction

Salesforce logoSalesforceFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem 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) → int

Examples

Example 1

n = 7return = 2

Add 1 to get 8, then subtract 8 to reach 0.

Example 2

n = 10return = 2

Subtract 8, then subtract 2.

Constraints

  • 0 < n < 2^60

More Salesforce Online Assessment questions

  • Count Subarrays With Product Equal to KOA · Seen Nov 2026
  • Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
  • Get Message StatusOA · Seen Nov 2026
  • Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
  • Run-Length String CompressionOA · Seen Sep 2026
  • Maximum Requests in WindowOA · Seen Sep 2026
  • Final Pod Counts After LogsOA · Seen Aug 2026
  • Minimum Removals to Balance ArrayOA · Seen Aug 2026
  • Is This Date a Weekend?OA · Seen Aug 2026
  • Maximum Barbell WeightOA · Seen Jul 2026

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int minimumEnergyReductionOperations(long n) {
      // write your code here
    }
}
Checking account…