Minimum Operations to Make the Integer Zero

You are given two integers num1 and num2.

In one operation, you can choose an integer i in the range [0, 60] and subtract 2^i + num2 from num1.

Return the integer denoting the minimum number of operations needed to make num1 equal to 0.

If it is impossible to make num1 equal to 0, return -1.

Example 1
Inputnum1 = 3, num2 = -2
Output3
We can make 3 equal to 0 in 3 operations, and it can be proven that 3 is the minimum number needed.
Example 2
Inputnum1 = 5, num2 = 7
Output-1
It can be proven that it is impossible to make 5 equal to 0 with the given operation.

Constraints

  • 1 <= num1 <= 10^9
  • -10^9 <= num2 <= 10^9

Asked at 4 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate