Ctrl K

Weakest-Link Crew Power

Hard
Workers stand in a row, and skill[i] is the skill of the i-th one. A crew is one or more workers standing next to each other. The power of a crew is the product of two numbers: the skill of its weakest member and the total skill of all its members. Return the sum of the powers of all possible crews modulo 10⁹ + 7.
Example 1
skill=[2, 4, 1] → 45

Crews: [2] → 2·2 = 4, [4] → 4·4 = 16, [1] → 1·1 = 1, [2, 4] → 2·6 = 12, [4, 1] → 1·5 = 5, [2, 4, 1] → 1·7 = 7. The sum is 45.

Example 2
skill=[3, 3] → 36

[3] → 9 twice and [3, 3] → 3·6 = 18, for 36 in total.

Example 3
skill=[10] → 100
Constraints
  • 1 ≤ len(skill) ≤ 10⁵
  • 1 ≤ skill[i] ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHard Shifts Take the Lead MediumWeakest Link Times Total MediumWater Between Walls HardBiggest Rectangle Under the Skyline HardBiggest Solid Panel Block Hard
loading Python…
Input
skill=[2, 4, 1]
Expected
45

Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.