1010. Min Times Sum

Medium3.5 points estimatedArrayMonotonic StackPrefix Sum3 hints

A bakery logs how many loaves each oven produced in a row of consecutive hours, stored in nums. The score of a non-empty run of consecutive hours is the smallest hourly count in the run multiplied by the total of all counts in the run.

Find the largest score over all runs and return it modulo 1000000007. The maximum must be compared as an exact number first, and only the final answer is reduced; with the bounds below the exact value fits in 64 bits (and below 9*10^15).

A run containing a zero scores 0, and every score is at least 0. Aim for O(n) time and O(n) space.

Example 1

Input:
nums = [14,9,31,7,22]
Output:
961
Explanation:

The best slice gives a value of 961.

Example 2

Input:
nums = [6,6,2,8]
Output:
72
Explanation:

The best slice gives a value of 72.

Constraints

1 ≤ nums.length ≤ 105

0 ≤ nums[i] ≤ 104

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Time per case
Python 2,000 msC++ 500 msJava 1,000 msJavaScript 1,000 msTypeScript 1,000 ms

Expected complexity

Time
O(n)
Space
O(n)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…