BackhardQueue

Sequence Optimization Problem Solution

Problem Statement

Given a sequence of operations with specific execution times and a constraint on the number of parallel processors, determine the optimal sequence of operations that minimizes the total execution time.

Example 1
Input
[10, 20, 30, 40, 50] with 2 parallel processors
Output
150

Explanation: To achieve the minimum execution time, the optimal sequence is ((10+20)+(30+40))+50, resulting in a total execution time of 150 units.

Example 2
Input
[5, 15, 25, 35] with 1 parallel processor
Output
80

Explanation: The sequence is executed sequentially due to the single processor constraint, resulting in a total execution time of 5+15+25+35 = 80 units.

Constraints

  • The number of parallel processors is limited and should be a non-negative integer.
  • Each operation's execution time is a non-negative integer.
  • The input sequence contains at least one operation and is a list of non-negative integers.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free