Mid/SeniorEnumerationMath

Minimum Cost to Set Cooking Time

A generic microwave supports cooking times for:

  • at least 1 second.
  • at most 99 minutes and 99 seconds.

To set the cooking time, you push at most four digits. The microwave normalizes what you push as four digits by prepending zeroes. It interprets the first two digits as the minutes and the last two digits as the seconds. It then adds them up as the cooking time.

You are given integers startAt, moveCost, pushCost, and targetSeconds. Initially, your finger is on the digit startAt. Moving the finger above any specific digit costs moveCost units of fatigue. Pushing the digit below the finger once costs pushCost units of fatigue.

There can be multiple ways to set the microwave to cook for targetSeconds seconds, but you are interested in the way with the minimum cost.

Return the minimum cost to set targetSeconds seconds of cooking time.

Remember that one minute consists of 60 seconds.

Example 1
InputstartAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600
Output6
Pushing 1 0 0 0 sets 10 minutes and 0 seconds for a total cost of 6, which is less than other valid representations such as 0960 or 960.
Example 2
InputstartAt = 0, moveCost = 1, pushCost = 2, targetSeconds = 76
Output6
The optimal way is to push 7 6, interpreted as 76 seconds, with total cost 1 + 2 + 1 + 2 = 6.

Constraints

  • 0 <= startAt <= 9
  • 1 <= moveCost, pushCost <= 10^5
  • 1 <= targetSeconds <= 6039

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate