Count Operations to Obtain Zero

You are given two non-negative integers num1 and num2.

In one operation, if num1 >= num2, you must subtract num2 from num1; otherwise, subtract num1 from num2.

Return the number of operations required to make either num1 = 0 or num2 = 0.

Example 1
Inputnum1 = 2, num2 = 3
Output3
After three operations, num1 becomes 0, so the total number of operations required is 3.
Example 2
Inputnum1 = 10, num2 = 10
Output1
Since num1 == num2, one operation subtracts num2 from num1, making num1 equal to 0.

Constraints

  • 0 <= num1, num2 <= 10^5

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate