<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:
    def maximumScore(self, nums: List[int], k: int) -> int:
        n=len(nums)
        new_num=[0]*n
        new_num[k]=nums[k]
        for i in range(k-1,-1,-1):
            new_num[i]=min(nums[i],new_num[i+1])
        for i in range(k+1,n):
            new_num[i]=min(nums[i],new_num[i-1])
        ls=[0]*n
        ls[0]=-1
        st1=[0]
        rs=[0]*n
        rs[n-1]=n
        st2=[n-1]
        for i in range(1,n):
            while(len(st1)>0 and new_num[i]<=new_num[st1[-1]]):
                st1.pop()
            if(len(st1)==0):
                ls[i]=-1
            else:
                ls[i]=st1[-1]
            st1.append(i)
            index=n-1-i
            while(len(st2)>0 and new_num[index]<=new_num[st2[-1]]):
                st2.pop()
            if(len(st2)==0):
                rs[index]=n
            else:
                rs[index]=st2[-1]
            st2.append(index)
        res=nums[k]
        for i in range(1,n):
            p=new_num[i]*(rs[i]-ls[i]-1)
            res=max(res,p)
        return res
        
1109