---
# System prepended metadata

title: 'Week.3.Dragon [1793. Maximum Score of a Good Subarray]'
tags: [leetcode]

---

---
image: https://leetcode.com/static/images/LeetCode_Sharing.png
tags: leetcode
---
# Week.3.Dragon [1793. Maximum Score of a Good Subarray]
---
- 給List, 數字k, 從第k位置開始找出最大值的subarray.
- 最大值算法: 為subarray內最小值*array大小
---
- 起點K, 如果左邊數字大, 往左擴, 反之往右擴, 請確認是否達到邊界點
- 重要, 每次去算最小值, 如果List超大, 運算時間才不會太久.
- 根據題意算出結果, 取最大值
---
```python!
class Solution:
    def maximumScore(self, nums: List[int], k: int) -> int:
        # 給List, 數字k, 從第k位置開始找出最大值的subarray.
        # 最大值為subarray內最小值*array大小
        l, r, n = k, k, len(nums)
        res = mini = nums[k]
        while r - l + 1 != n:
            # 如果左邊數字大, 往左擴, 反之往右擴
            # 需要額外確認是否達到邊界點
            if (nums[l-1] if l else 0) > (nums[r+1] if r<n-1 else 0):
                l -= 1
            else:
                r += 1
            # 重要, 如果List超大, 運算時間才不會太久.
            mini = min(mini, nums[l], nums[r])
            # 根據題意算出結果, 取最大值
            res = max(res, mini*(r-l+1) )
        return res
```
[1793. Maximum Score of a Good Subarray]:https://leetcode.com/problems/maximum-score-of-a-good-subarray/description/
