Maximum Performance of a Team - Problem

You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n.

speed[i] and efficiency[i] represent the speed and efficiency of the i-th engineer respectively.

Choose at most k different engineers out of the n engineers to form a team with the maximum performance.

The performance of a team is the sum of its engineers' speeds multiplied by the minimum efficiency among its engineers.

Return the maximum performance of this team. Since the answer can be a huge number, return it modulo 109 + 7.

Input & Output

Example 1 — Basic Case
$ Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2
Output: 60
💡 Note: We choose engineers 2 and 5 (0-indexed) with speeds [10,5] and efficiencies [4,7]. Performance = (10+5) × min(4,7) = 15 × 4 = 60.
Example 2 — Single Engineer
$ Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3
Output: 68
💡 Note: Choose engineer with efficiency 9 and speed 1, plus top 2 others by speed considering efficiency constraint. Best combination gives performance 68.
Example 3 — All Engineers
$ Input: n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 6
Output: 72
💡 Note: When k equals n, we can consider all engineers. The optimal team maximizes sum of speeds × minimum efficiency across all possible combinations.

Constraints

  • 1 ≤ n ≤ 105
  • 1 ≤ speed[i] ≤ 105
  • 1 ≤ efficiency[i] ≤ 108
  • 1 ≤ k ≤ n

Visualization

Tap to expand
Maximum Performance: Select Best Team of EngineersPerformance = (Sum of Speeds) × (Minimum Efficiency)Engineer 0Speed: 2Efficiency: 5Engineer 1Speed: 10Efficiency: 4Engineer 2Speed: 3Efficiency: 3Engineer 3Speed: 1Efficiency: 9Engineer 4Speed: 5Efficiency: 7Engineer 5Speed: 8Efficiency: 2Available EngineersSelected Team (k=2)Team Performance Calculation:Speed Sum: 1 + 5 = 6Minimum Efficiency: min(9, 7) = 7Performance: 6 × 7 = 42Goal: Find team with maximum performance
Understanding the Visualization
1
Input
Engineers with speed and efficiency values, team size k
2
Process
Find optimal team that maximizes sum of speeds × minimum efficiency
3
Output
Maximum performance value modulo 10^9 + 7
Key Takeaway
🎯 Key Insight: Sort by efficiency descending, then greedily pick top k speeds using a min-heap to try every possible minimum efficiency
Asked in
Google 15 Amazon 12 Facebook 8 Microsoft 6
156.0K Views
Medium Frequency
~35 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen