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 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
