Google | Onsite | Min operations to reduce number to 1
15272
Mar 14, 2020
May 05, 2020
Given a positive integer n and 3 operations on n:
- n - 1
- n / 2 (if n is even)
- n / 3 (if n % 3 == 0)
Find the minimum number of above operations to reduce n to 1.
Example 1:
Input: n = 9
Output: 2
Explanation:
Step 1: 9 / 3 = 3
Step 2: 3 / 3 = 1Example 2:
Input: n = 8
Output: 3
Explanation:
Step 1: 8 / 2 = 4
Step 2: 4 / 2 = 2
Step 3: 2 - 1 = 1Example 3:
Input: n = 28
Output: 4Comments (29)


