Ctrl K

Weakest Link Times Total

Medium
You get an array of positive integers loads. For a contiguous non-empty segment, take its minimum and its sum and multiply them; call that the segment's score. For example, the segment [4, 2, 7] scores 2 · (4 + 2 + 7) = 26. Return the largest score over all segments modulo 10⁹ + 7. Maximise the actual value first and only then take the remainder. The maximum before the remainder is guaranteed to fit in a signed 64-bit integer.
Example 1
loads=[4, 1, 6, 5, 3] → 55

The segment [6, 5] has minimum 5 and sum 11, giving 55. [6, 5, 3] gives 3 · 14 = 42 and [6] gives 36; nothing beats 55.

Example 2
loads=[2, 2, 2] → 12

Take the whole array: 2 · 6 = 12.

Example 3
loads=[1, 9, 1] → 81

The single element 9 gives 9 · 9 = 81, while the whole array gives only 1 · 11 = 11.

Constraints
  • 1 ≤ len(loads) ≤ 10⁵
  • 1 ≤ loads[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 Crew Power HardPreorder of a Search Tree MediumLow, Peak, Middle MediumNext Larger Around the Circle Medium
loading Python…
Input
loads=[4, 1, 6, 5, 3]
Expected
55

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