Simple With Explanation 
Intuitionfor every i index from 1 to n-1 including we just have to check two conditions in O(1) timeApproachfirst condition
if all the elements befor i  is smal
# Intuition
  for every i index from 1 to n-1 including we just have to check two conditions in O(1) time

# Approach
  first condition 
  if all the elements befor i  is smaller then i th element and all the element after ith element are bigger than the ith element then add 2

second condition 
if first condition is not true then we have to check if the element just before the ith element is smaller then ith element and the element just after the ith element is bigger then add 1 to answer


so second condition could be checked easily

for first condition we will make two arrays one that will calculate the biggest element till now from the left side we call if pref

and for that calculates smallest element till now from right and we call it suffix

now we have smallest element of right side and biggest element of left side now the first condition could be checked easily

# Complexity
- Time complexity:
 O(n)

- Space complexity:
 O(n)

# Code
```cpp []
class Solution {
public:
    int sumOfBeauties(vector<int>& nums) {
        int beauty = 0;
        int n = nums.size();
        vector<int>pref(n,0);
        pref[0] = nums[0];
        vector<int>suff(n,0);
        suff[n-1] = nums[n-1];
        for(int i = 1;i<n;i++){
            pref[i] = max(pref[i-1],nums[i]);
            suff[n-i-1] = min(suff[n-i],nums[n-i-1]);
        }
        for(int i = 1;i<n-1;i++){
            if(pref[i-1] < nums[i] && suff[i+1] > nums[i])beauty+=2;
            else if(nums[i-1] < nums[i] && nums[i] < nums[i+1])beauty+=1;
        }
        return beauty;
    }

   
};
```
['Suffix Array', 'Prefix Sum', 'C++']