Broken Calculator
MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.A broken calculator shows start_value and has only two buttons: double the number, or subtract 1. Return the minimum number of presses to show target.
start_value = 2, target = 3 → 2 (double, then subtract: 2 → 4 → 3)
start_value = 5, target = 8 → 2 (subtract, then double: 5 → 4 → 8)
start_value = 3, target = 10 → 3 (3 → 6 → 5 → 10)Constraints
1 <= start_value, target <= 10^9