Prefix Suffix Sum
IntuitionPrefix Suffix SumCode
# Intuition
Prefix Suffix Sum

# Code
```java []
class Solution {
    public int sumOfBeauties(int[] nums) {
        int[] prefix = new int[nums.length];
        int[] suffix = new int[nums.length];
        prefix[0] = nums[0];
        suffix[suffix.length-1] = nums[nums.length-1];
        for(int i=1;i<nums.length;i++) {
            prefix[i] = Math.max(prefix[i-1], nums[i]);
        }
        for(int i=nums.length-2;i>=0;i--) {
            suffix[i] = Math.min(suffix[i+1], nums[i]);
        }

        int sum = 0;
        for(int i=1;i<=nums.length-2;i++) {
            if(nums[i]>prefix[i-1] && nums[i]<suffix[i+1]) {
                sum=sum+2;
            } else if(nums[i]>nums[i-1] && nums[i]<nums[i+1]) {
                sum=sum+1;
            }
        }
        return sum;
    }
}
```
['Java']