991. Broken Calculator

Medium

2.5K

202

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*.

**Example 1:**

Input:startValue = 2, target = 3Output:2Explanation:Use double operation and then decrement operation {2 -> 4 -> 3}.

**Example 2:**

Input:startValue = 5, target = 8Output:2Explanation:Use decrement and then double {5 -> 4 -> 8}.

**Example 3:**

Input:startValue = 3, target = 10Output:3Explanation:Use double, decrement and double {3 -> 6 -> 5 -> 10}.

**Constraints:**

`1 <= startValue, target <= 10`

^{9}

Accepted

94K

Submissions

173.6K

Acceptance Rate

54.2%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved