A notification badge shows a counter n. In one step you may subtract 1 from it, halve it if it is even, or divide it by 3 if it is a multiple of 3.
Write fewestShrinkSteps(n) that returns the fewest steps needed to bring the counter down to exactly 1.
Input: n = 10 Output: 3
10 → 9 → 3 → 1. Halving first (10 → 5 → 4 → 2 → 1) takes 4 steps.
Input: n = 6 Output: 2
6 → 2 → 1, or 6 → 3 → 1.
1 <= n <= 100000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #492 Shrink a Counter to One. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.