Answer: STASHFIN Off-Campus OA (2024) | Count Operations to Obtain Zero
Answer · Posted Jun 2026
Approach 1: Direct Simulation Simulate the process exactly as described. At each step: Subtract the smaller number from the larger number. Increment the operation count. Stop when either number becomes zero. Strategy Initialize ops = 0. While both numbers are non-zero: Subtract the smaller from the larger. Increment ops. Return ops. Java Code: class Solution { public int countOperations(int num1, int num2) { int ops = 0; while (num1 != 0 && num2 != 0) { if (num1 >= num2) ...
The full answer & interview discussion are available to premium members.
Log in Create a free account