Ctrl K

Microwave Keypad Effort

Medium
A microwave timer is set by typing one to four digits. The digits are padded with zeros on the left to four: the first two are minutes, the last two are seconds, and the cooking time is minutes × 60 + seconds. Both minutes and seconds may be anything from 00 to 99, so typing 1 9 0 means 1 minute 90 seconds, i.e. 150 seconds. Your finger starts above digit start_digit. Moving the finger to a different digit costs move_cost, and pressing the digit under the finger costs press_cost. Return the minimum effort needed to set exactly seconds seconds.
Example 1
start_digit=5, move_cost=3, press_cost=1, seconds=90 → 8

Typing 1 3 0 (1 min 30 s) costs 3+1 + 3+1 + 3+1 = 12, while 9 0 (0 min 90 s) costs 3+1 + 3+1 = 8. The answer is 8.

Example 2
start_digit=4, move_cost=10, press_cost=2, seconds=44 → 4

The finger is already on 4: press it twice without moving. 2 + 2 = 4.

Example 3
start_digit=0, move_cost=1, press_cost=5, seconds=6039 → 21
Constraints
  • 0 ≤ start_digit ≤ 9
  • 1 ≤ move_cost, press_cost ≤ 10⁵
  • 1 ≤ seconds ≤ 6039
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumShuffle the Digits Into a Power of Two MediumSums of Two Powers MediumA Multiple Spelled With Two Digits MediumNotebooks and Markers Medium
loading Python…
Input
start_digit=5, move_cost=3, press_cost=1, seconds=90
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.