986. Best Good Window
A photographer stores the brightness of every shot on a film strip in nums. The score of a contiguous run of shots nums[i..j] is the dimmest brightness in the run multiplied by the number of shots in the run. A run is acceptable only if it contains the shot at index k (0-indexed), i.e. i <= k <= j.
Return the maximum score over all acceptable runs. A run of one shot (just index k) is always acceptable.
Example 1
- Input:
- nums = [6,2,9,4,5], k = 2
- Output:
- 12
- Explanation:
Window indices 2..4 holds 9, 4, 5: the smallest is 4 and the width is 3, giving 12. Wider windows drop to a smaller minimum and score less.
Example 2
- Input:
- nums = [3,3,3], k = 1
- Output:
- 9
- Explanation:
The whole array has minimum 3 and width 3, so the best score is 9.
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 2 * 104
- 0 ≤ k < nums.length
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 600 msC++ 150 msJava 300 msJavaScript 300 msTypeScript 300 ms
Expected complexity
- Time
- O(n)
- Space
- O(1)