<p>You are given an array of integers <code>nums</code> <strong>(0-indexed)</strong> and an integer <code>k</code>.</p>

<p>The <strong>score</strong> of a subarray <code>(i, j)</code> is defined as <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code>. A <strong>good</strong> subarray is a subarray where <code>i &lt;= k &lt;= j</code>.</p>

<p>Return <em>the maximum possible <strong>score</strong> of a <strong>good</strong> subarray.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,4,3,7,4,5], k = 3
<strong>Output:</strong> 15
<strong>Explanation:</strong> The optimal subarray is (1, 5) with a score of min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15. 
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [5,5,4,5,4,1,1,1], k = 0
<strong>Output:</strong> 20
<strong>Explanation:</strong> The optimal subarray is (0, 4) with a score of min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 2 * 10<sup>4</sup></code></li>
	<li><code>0 &lt;= k &lt; nums.length</code></li>
</ul>

class Solution:
    # [1]
    # [1 4]
    # [1 4 3] => [1 3], right = 2, mid = 1, left = 0, 4 is the min of [0 + 1, 2 - 1]
    # [1 3 7]
    # [1 3 7 4] => [1 3 4], right = 4, mid = 3, left = 2, 7 is the min of [2 + 1, 4 - 1]
    # [1 3 4 5] 
    # right = 6, mid = 5, left = 4 => 5 is the min of [4 + 1, 6 - 1]
    # [1 3 4]
    # right = 6, mid = 4, left = 2 => 4 is the min of [2 + 1, 6 - 1]
    # [1 3]
    # right = 6, mid = 2, left = 0 => 3 is the min of [0 + 1, 6 - 1]
    # [1]
    # right = 6, mid = 0, left = -1 => 1 is the min of [-1 + 1, 6 - 1]
    # left < k < right is good
    def maximumScore(self, nums: List[int], k: int) -> int:
        res = 0
        stack = []
        length = len(nums)
        for i in range(length + 1):
            while stack and (i == length or nums[stack[-1]] >= nums[i]):
                right = i
                mid = stack.pop()
                left = stack[-1] if stack else -1
                if left < k < right:
                    res = max(res, nums[mid] * (right - left - 1))
            stack.append(i)
        return res
823