Problem: Find Optimal Input
You are tasked with determining the optimal microwave input for a target cooking time, considering both the cost of input and the target time. The input time is provided in the form of key strokes that represent minutes and seconds. The goal is to find an input whose cost is minimized and whose value is within 10% of the target cooking time.
Problem Description:
Given the following:
- Input Interpretation:
- An input of
999
is interpreted as 9 minutes and 99 seconds. - An input of
81
is interpreted as 81 seconds. - An input of
1221
is interpreted as 12 minutes and 21 seconds.
- An input of
- Cost of Input:
- The cost of each key stroke is 1.
- The cost of moving the finger to a different key is 2.
- The input
999
has a cost of 3 (one key stroke per digit, and moving the finger between 9 and 9 counts as 2 for each transition). - The input
1122
has a cost of 6. - The input
1234
has a cost of 10.
- Constraints:
- The input must be within 10% of the target cooking time.
- If there are multiple inputs with the same cost, select the input closest to the target time.
- Objective:
- Find the input that minimizes the cost and is within 10% of the target time.
Function Description:
Write a function findOptimalInput
that receives the targetTime
(in seconds) and returns the optimal input.
Function Signature:
def findOptimalInput(targetTime: int) -> int:
Input:
- targetTime: an integer representing the target cooking time in seconds.
Output:
- int: the optimal input value.
Example:
Example 1:
Input:
targetTime = 600
Output:
888
Explanation:
- For a target time of 10 minutes (600 seconds), the optimal input is
888
, which is interpreted as 8 minutes 88 seconds, or 528 seconds. This is within 10% of the target time and has a lower cost than999
, which would be interpreted as 9 minutes 99 seconds (599 seconds).
Constraints:
- The target time is within a reasonable range (e.g., between 1 and 10,000 seconds).
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.