FastPrepMinimum Operations to Zero
Problems/Minimum Operations to Zero

Minimum Operations to Zero

Salesforce logoSalesforceFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an integer n. In one operation, you may add or subtract any power of two from n, such as 2^0, 2^1, 2^2, and so on.

Return the minimum number of operations required to reduce n to 0.

Function

getMinOperations(n: int) → int

Examples

Example 1

n = 21return = 3

One optimal sequence is 21 -> 20 by subtracting 1, 20 -> 16 by subtracting 4, and 16 -> 0 by subtracting 16.

Constraints

  • 1 <= n <= 10^9

More Salesforce Online Assessment questions

  • Count Subarrays With Product Equal to KOA · Seen Dec 2026
  • Get Minimum TimeOA · 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

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 getMinOperations(int n) {
      // write your code here
    }
}
Checking account…