Beats 90% easy cpp solution
IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
   $$O(n)$$ 

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int sumOfBeauties(vector<int>& nums) {

        int n=nums.size();
        vector<int>maxarr(n,0);
        vector<int>minarr(n,0);
        int maxi=INT_MIN;
        int mini=INT_MAX;

        for(int i=0;i<n;i++)
        {
            maxarr[i]=max(maxi,nums[i]);
            maxi=maxarr[i];
        }
        for(int i=n-1;i>=0;i--)
        {
            minarr[i]=min(mini,nums[i]);
            mini=minarr[i];
        }
        int count=0;
        for(int i=1;i<=n-2;i++)
        {
            if(nums[i]<minarr[i+1] && nums[i]>maxarr[i-1])
            {
                count=count+2;
            }
            else if(nums[i - 1] < nums[i] && nums[i] < nums[i + 1])
            {
                count=count+1;
            }
        }

        return count;
        
    }
};
```
['Prefix Sum', 'C++']