Maximum Subarray Min-Product
Real-world version: Weakest Link Times the LoadThe statement here is our own: the same inputs, outputs and technique.
A run of couplings has strengths nums. For any contiguous stretch of it, the stretch's grade is the smallest strength in that stretch multiplied by the total of the strengths in it.
Return the largest grade over every non-empty contiguous stretch, modulo 10^9 + 7.
Examples
Example 1
- Input
- nums = [4, 11, 7, 2, 9, 6]
- Output
- 126
The stretch 11, 7 has smallest strength 7 and totals 18, giving 126. Nothing beats it: reaching one further left drops the weakest link to 4, and reaching right drops it to 2. The best stretch on the other side, 9 and 6, only reaches 90.
Example 2
- Input
- nums = [1, 9, 9, 9, 1]
- Output
- 243
The three nines in the middle have smallest strength 9 and total 27, giving 243. Reaching out to either 1 would cut the weakest link to 1.
Example 3
- Input
- nums = [1000000, 1000000, 1000000, 1000000]
- Output
- 999972007
The whole run is the best stretch, and its grade is a million times four million, which leaves this remainder once reduced.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^6
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def max_sum_min_product(nums: list[int]) -> int:public int maxSumMinProduct(int[] nums)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Sum of Total Strength of WizardsReal-world version: Total Yield of Every Turbine StretchHard
- Next Greater Element IReal-world version: Auction Watchlist HighsEasy
- Final Prices With a Special Discount in a ShopReal-world version: Job Hour CreditsEasy
- Daily TemperaturesReal-world version: Nights Until a Fuller HouseMedium