Facebook Pixel

Sum of Subarray Minimum

JavaScript
medium
40 mins

Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo (10^9 + 7).

Example Inputs & Outputs

// Example 1: Input: s = "the sky is blue" Output: "blue is sky the" // Example 2: Input: s = " hello world " Output: "world hello" Explanation: Your reversed string should not contain leading or trailing spaces. // Example 3: Input: s = "a good example" Output: "example good a" Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.

Constraints

  • 1 <= arr.length <= 3 * 10^4
  • 1 <= arr[i] <= 3 * 10^4

Edge Cases

  • The array contains positive integers only.
  • The result must be computed modulo (10^9 + 7).
  • Single element array should return the element itself.
  • Arrays with identical elements or repeating patterns may require careful handling to avoid overflow.

Companies:

amazon
apple
google
microsoft

Solve Similar questions šŸ”„