Java Solution | Prefix Maximum | Suffix Minimum
Code
# Code
```java []
class Solution {
    public int sumOfBeauties(int[] nums) {
        int n = nums.length;
        int[] left = new int[n];
        int[] right = new int[n];

        left[0] = Integer.MIN_VALUE;
        for(int i = 1;i<n;i++){
            left[i] = Math.max(left[i-1], nums[i-1]);
        }

        right[n-1] = Integer.MAX_VALUE;

        for(int i = n-2;i>=0;i--){
            right[i] = Math.min(right[i+1], nums[i+1]);
        }

        int sum = 0;

        for(int i = 1;i<n-1;i++){
            if(left[i] < nums[i] && right[i] > nums[i]){
                sum += 2;
            }else if(nums[i-1] < nums[i] && nums[i] < nums[i+1]){
                sum += 1;
            }
        }

        return sum;
    }
}
```
['Java']