Minimum Cost to Set Cooking Time
expert · 1055 · lc medium +32 · verified · 41.5% accepted · 236 likes · top 22%
Description
A microwave supports cooking times of:
- At least 1 second.
- At most 99 minutes and 99 seconds.
To enter a cooking time, you press up to four digits. The microwave pads the input to four digits with leading zeros, interprets the first two as minutes and the last two as seconds, and adds them together. For example:
- Pressing 9 5 4 is normalized to 0954: 9 minutes and 54 seconds.
- Pressing 0 0 0 8 gives 0 minutes and 8 seconds.
- Pressing 8 0 9 0 gives 80 minutes and 90 seconds.
- Pressing 8 1 3 0 gives 81 minutes and 30 seconds.
You are given startAt, moveCost, pushCost, and targetSeconds. Your finger begins at digit startAt. Moving to a different digit costs moveCost fatigue units; pushing the current digit costs pushCost fatigue units.
Return the minimum total fatigue cost to enter a time equal to targetSeconds.
Recall that one minute is 60 seconds.
Example 1:
Example 2:
Code