Having max prefix and min prefix || O(N) || Beats 100% || Python
Code


# Code
```python3 []
class Solution:
    def sumOfBeauties(self, nums: List[int]) -> int:
        m=[]
        t=nums[0]
        s=0
        for i in range(1,len(nums)-1):
            if nums[i]>t:
                m.append(1)
                t=nums[i]
            else:
                m.append(0)
        t=nums[len(nums)-1]
        for i in range(len(nums)-2,0,-1):
            if nums[i]<t and m[i-1]:
                s+=2
            elif nums[i]>nums[i-1] and nums[i]<nums[i+1]:
                s+=1
            if nums[i]<t:
                t=nums[i]
        return s


```
['Python3']