 Sum of Beauty in the Array
Complexity
Time complexity:O(1)

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

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

# Code
```java []
class Solution {
    public int sumOfBeauties(int[] nums) {
        int n = nums.length;
        int totalBeauty = 0;
        int minRight = Integer.MAX_VALUE;
        int[] minRightArr = new int[n];
        for(int i=n-1; i>=0; i--){
            minRight = Math.min(minRight, nums[i]);
            minRightArr[i] = minRight; 
        }
        int maxLeft = nums[0];
        for(int i = 1; i<n-1; i++){
            if(nums[i] > maxLeft && nums[i] < minRightArr[i+1]){
                totalBeauty += 2;
            }else if(nums[i-1] < nums[i] && nums[i] < nums[i+1]){
                totalBeauty += 1;
            }
            maxLeft = Math.max(maxLeft, nums[i]);
        }
        return totalBeauty;
    }
}
```
['Java']