We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 227b80f commit a969646Copy full SHA for a969646
501-1000/907.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def sumSubarrayMins(self, arr: List[int]) -> int:
3
+ ans = 0
4
+ stack = []
5
+ arr = [float('-inf')] + arr + [float('-inf')]
6
+ for i, n in enumerate(arr):
7
+ while stack and arr[stack[-1]] > n:
8
+ cur = stack.pop()
9
+ ans += arr[cur] * (i - cur) * (cur - stack[-1])
10
+ stack.append(i)
11
+ return ans % (10**9 + 7)
12
+
0 commit comments