1. Minimum Total Weight
You have n chocolates with weights given in an array weights[n], where weights[i] represents the weight of the iᵗʰ chocolate. Each day, you can pick one chocolate, consume half of its weight (calculated as floor(weights[i] / 2)), and keep the remaining portion.
Calculate the minimum possible total weight of the chocolates after d days. Note that you can eat from the same chocolate multiple times.
Example
Input:
weights = [20, 30, 25]
d = 4
Table of Weight Reduction Process:
Day | Weight of the Chocolate Picked | Weight Eaten | Remaining Weight | Result |
---|---|---|---|---|
1 | 20 | 10 | 10 | [30, 10, 25] |
2 | 25 | 12 | 13 | [30, 10, 13] |
3 | 30 | 15 | 15 | [15, 10, 13] |
4 | 15 | 7 | 8 | [8, 10, 13] |
The total weight of chocolates on day 4 is 8 + 10 + 13 = 31, which is the minimum possible weight after 4 days.
Function Description
Complete the function findMinWeight in the editor below.
Function Signature:
def findMinWeight(weights: List[int], d: int) -> int:
Parameters:
- weights: A list of integers representing the initial weights of chocolates.
- d: An integer representing the number of days chocolates are consumed.
Returns:
- int: The minimum total weight of chocolates after d days.
2. Vowel Substring
Given a string composed of lowercase letters within the ASCII range 'a'-'z', determine the number of substrings that consist solely of vowels, where each vowel appears at least once. The vowels are {'a', 'e', 'i', 'o', 'u'}. A substring is defined as a contiguous sequence of characters within the string.
Example
Input:
s = "aeioeaxaaeiou"
Explanation:
There is a substring to the left that is made of vowels, "aeioae"
, which is followed by "x"
.
"x"
cannot be included in the substring, and this substring does not contain all vowels.- It is not a qualifying substring.
Moving to the right, there are four substrings that qualify:
"aaeiou"
"aeiou"
"aeoiu"
"aeuio"
Thus, the output is 4.
Function Description
Complete the function vowelSubstring in the editor below.
Function Signature:
def vowelSubstring(s: str) -> int:
Parameters:
- s: A string composed of lowercase English letters.
Returns:
- int: The number of substrings that consist of vowels only (
'a', 'e', 'i', 'o', 'u'
) where every vowel appears at least once.
Constraints:
- 1 ≤ size_of_s ≤ 10⁵
- s[i] is in the range 'a'-'z' for all 0 ≤ i < size_of_s.
3. Task Scheduling
The data analysts of Hackerland want to schedule some long-running tasks on remote servers optimally to minimize the cost of running them locally. The analysts have two servers:
- A paid server
- A free server
The free server can only be used if the paid server is occupied.
Problem Statement
The iᵗʰ task is expected to take time[i] units of time to complete, and the cost of processing the task on the paid server is cost[i].
- The task can be run on the free server only if some task is already running on the paid server.
- The cost of the free server is 0, and it can process any task in 1 unit of time.
Find the minimum cost to complete all the tasks if tasks are scheduled optimally.
Example
Input:
n = 4
cost = [1, 1, 3, 4]
time = [3, 1, 2, 3]
Explanation:
- The first task must be scheduled on the paid server for a cost of 1.
- It takes 3 units of time to complete.
- In the meantime, the other three tasks are executed on the free server for no cost.
- The free server takes only 1 unit of time to complete any task.
Thus, the total cost = 1.
Output:
1
Function Description
Complete the function getMinCost in the editor below.
Function Signature:
def getMinCost(cost: List[int], time: List[int]) -> int:
Parameters:
- cost: A list of integers, where
cost[i]
is the cost of scheduling the iᵗʰ task on the paid server. - time: A list of integers, where
time[i]
is the time taken to run the iᵗʰ task on the remote server.
Returns:
- int: The minimum cost required to complete all tasks.
我们长期稳定承接各大科技公司如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.
