A map widget has three zoom buttons: "+1" adds one to the zoom level, "-1" subtracts one, and "x2" doubles it. The zoom level can never go below 0 or above 2000, so a press that would leave that range does nothing useful and isn't allowed.
Write fewestPresses(start, target) that returns the fewest button presses needed to change the zoom level from start to target.
Input: start = 3, target = 10 Output: 3
For example 3 → 4 → 5 → 10 (+1, +1, x2). Two presses from 3 can only reach 1, 3, 4, 5, 7, 8, or 12.
Input: start = 5, target = 5 Output: 0
The zoom level is already right.
0 <= start, target <= 1000Run 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 #430 Fewest Zoom Presses. 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.