Skip to content

Practice Broken Calculator

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#991
LeetCode Problem

Broken Calculator

Problem Statement

The calculator initially displays startValue. Each operation either doubles the displayed integer or subtracts 1. Return the minimum operations required to display target.

Source: Broken Calculator on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
startValue = 2, target = 3
Output
2

# Example 2

Input
startValue = 5, target = 8
Output
2

# Example 3

Input
startValue = 3, target = 10
Output
3

Constraints

1 <= startValue, target <= 10^9

Related LeetCode Problems

Practice more problems similar to Broken Calculator.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.