LeetCode 991, Medium. Topics: Math, Greedy. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:
Problem
There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:
- multiply the number on display by
2, or
- subtract
1 from the number on display.
Given two integers startValue and target, return the minimum number of operations needed to display target on the calculator.
Examples
Constraints
- 1 <= startValue, target <= 10^9
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026