Get Minimum Time
Learn this problemProblem statement
Given n processes that need to be executed. Among these n processes,
k are classified as high-priority processes, with their indices (1-based) represented
in the array as high_priority[i].
An OS scheduler is responsible for overseeing the execution of all processes. When a scheduler assigns a set of processes to a processor, it has two options:
p, into two contiguous subarrays of equal length, p1 and
p2, such that p = [p1, p2]. The scheduler will then allocate p1
to one processor and p2 to another.p.
The time required for process execution is determined based on the following criteria:
👉 1. If the assigned processes do not include any high-priority processes, the scheduler will take
normal_time seconds to complete all the assigned processes.
👉 2. If there are high-priority processes among the assigned tasks (denoted as x), it
will take (priority_time * x * l) seconds to complete them, where l is
the total number of assigned processes.
The total time required to execute all processes is the sum of the time taken by all processors for their assigned tasks. The task is to minimize the total execution time by optimizing the assignment of processes to processors within the operating system and return this minimum possible execution time.
Function
getMinimumTime(n: int, high_priority: int[], normal_time: int, priority_time: int) → int
Complete the function getMinimumTime in the editor below.
getMinimumTime takes the following parameters:
int n: the total number of processesint high_priority[k]: the indices of the high-priority processesint normal_time: the time factor for completing non-high-priority processesint priority_time: the time factor for completing high-priority processes
Returns
int: the minimum total execution time by optimizing the assignment of processes to
processors within the operating system
Examples
Example 1
n = 4high_priority = [1]normal_time = 2priority_time = 2return = 6Constraints
1 ≤ n ≤ 10^9nis a power of 21 ≤ k ≤ min(n, 10^5)1 ≤ high_priority[i] ≤ n
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026