Dsa
Recursion
Warm-up
The Path to Unity
You are trying to reduce a positive integer N to 1. If N is even, you must divide it by 2. If N is odd, you must subtract 1. Use recursion to calculate the total number of steps required to reach 1.
Input: A single integer N.
Output: An integer representing the count of operations.
Example:
Input: 10
Output: 4
(Explanation: 10 -> 5 -> 4 -> 2 -> 1, which is 4 steps)
Key concepts
recursionmathoptimization
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now