Leetcode Problem 2162. Minimum Cost to Set Cooking Time

2162. Minimum Cost to Set Cooking Time

Leetcode Solutions

Optimal Time Setting with Two Choices

  1. Calculate the initial minutes (mins) and seconds (secs) from targetSeconds by dividing and taking the remainder with 60.
  2. Define a function cost that calculates the cost of setting the microwave to a given minutes and seconds.
  3. Normalize the input by converting minutes and seconds to a 4-digit string, prepending zeros if necessary.
  4. Calculate the cost of moving and pushing buttons based on the current finger position, moveCost, and pushCost.
  5. Use the cost function to calculate the cost for the exact minutes and seconds, and for one minute less with 60 additional seconds.
  6. Return the minimum of the two calculated costs.
UML Thumbnail

Brute Force Time Setting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...