Home / Expert Answers / Computer Science / 4-maximizing-task-priority-bytedance-is-working-on-a-new-algorithm-that-operates-on-a-special-c-pa653

(Solved): 4. Maximizing Task Priority ByteDance is working on a new algorithm that operates on a special C ...



4. Maximizing Task Priority
ByteDance is working on a new algorithm that
operates on a special CPU that can handle n types
of tasks, and the priority of the th task is
represented by the array priority[i]. The CPU will
run for y seconds and you can choose any task to
perform which follows the given conditions:
• In each second, you user can choose to perform
any available task from the n types (if there are any
tasks to perform).
• It is allowed to perform multiple tasks of the same
type within the given time frame, but there is a time
constraint that there must be at least x seconds
between any two consecutive tasks of the same
type.
• It is not allowed to perform more than one task at
any second.
Given n tasks, an array priority, and an integer x
and y, find the maximum possible sum of the
priority of tasks performed during the y seconds.
What will the Python code be for this question?

student submitted image, transcription available below

student submitted image, transcription available below

Given, , priority , and . can get is equal to 11 . We performed the task of the type then till the second 5 we cannot perform the task of the type again because of the time constraint , from the 6 th second we can perform the task of the type. The same applies to the task of the type as we once performed it in the second, and then till the second, we Complete the function maximumPrioritySum in the editor below. maximumPrioritySum has the following parameters: - int priority[n]: an array of integers representing the priorities of each task. - int . an integer denoting the minimum time constraint between every 2 tasks of the same type to be performed. - int . an integer denoting the number of seconds the CPU will run. Returns int: the maximum possible sum of the priority of tasks performed during the seconds. Constraints - priority[i] - -


We have an Answer from Expert

View Expert Answer

Expert Answer




We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe