Grokking the Engineering Manager Coding Interview
Ask Author
Back to course home

0% completed

Sum of Subarray Minimums (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an array of integers arr, return the sum of the minimum values from all possible contiguous subarrays within arr. Since the result can be very large, return the final sum modulo (10<sup>9</sup> + 7).

Examples

Example 1:

  • Input: arr = [3, 1, 2, 4, 5]
  • Expected Output: 30
  • Explanation:
    • The subarrays are: [3], [1], [2], [4], [5], [3,1], [1,2], [2,4], [4,5], [3,1,2], [1,2,4], [2,4,5], [3,1,2,4], [1, 2, 4, 5], [3, 1, 2, 4, 5].
    • The minimum values of these subarrays are:

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible