Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Reduce an Integer to 0

Minimum Operations to Reduce an Integer to 0 gives a positive integer and lets you add or subtract powers of two. Return the fewest operations needed to reach zero.

Statement

Given a positive integer n, you may repeatedly perform the following operation any number of times.

In one operation, choose a nonnegative integer i and either add 2i2^i to n or subtract 2i2^i from n.

Return the minimum number of operations required to make n equal to 00.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Reduce an Integer to 0

Minimum Operations to Reduce an Integer to 0 gives a positive integer and lets you add or subtract powers of two. Return the fewest operations needed to reach zero.

Statement

Given a positive integer n, you may repeatedly perform the following operation any number of times.

In one operation, choose a nonnegative integer i and either add 2i2^i to n or subtract 2i2^i from n.

Return the minimum number of operations required to make n equal to 00.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5