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: arr = [11, 81, 94, 43, 3] Output: 444 // Example 2: Input: arr = [2,2,2] Output: 12

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 🔥

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.