Task Scheduling
Learn this problemProblem statement
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 one and a free one. The free server can be used only if the paid server is occupied.
The nth task is expected to take time[n] units of time to complete and the cost of processing the task on the paid server is cost[n]. 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.
Function
snowflakegetMinCost(cost: int[], time: int[]) → int
Complete the function getMinCost in the editor.
The function getMinCost has the following parameter:
int cost[n]: the costs of scheduling the tasks on a remote serverint time[n]: the times taken to run the tasks on a remote server
Return:
int: the minimum cost to complete all the tasks
Possible solution hint: Need an O(n2) DP, in the form of DFS to judge one by one, which is equivalent to traversing all the cases ☕️ :)
Examples
Example 1
cost = [1, 1, 3, 4]time = [3, 1, 2, 3]return = 1Example 2
cost = [1, 2, 3, 2]time = [1, 2, 3, 2]return = 3Constraints
1 ≤ n ≤ 1051 ≤ cost[i] ≤ 1061 ≤ time[i] ≤ 107
More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across Nested String ListsPHONE SCREEN · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026