Easy Java || O(n) || Beats 97.87% || Memory 92%
IntuitionApproachComplexity
Time complexity: O(n)

Space complexity: O(n)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

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

# Complexity
- Time complexity: O(n)
<!-- 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[] leftMax=new int[nums.length];
        int[] rightMin=new int[nums.length];
        int temp=nums[0];
        for(int i=1;i<nums.length;i++){
            leftMax[i]=temp;
            if(temp<nums[i])temp=nums[i];
        }
        temp=nums[nums.length-1];
        for(int i=nums.length-2;i>=0;i--){
            rightMin[i]=temp;
            if(temp>nums[i])temp=nums[i];
        }
        int ansC=0;
        for(int i=1;i<=nums.length-2;i++){
            if(leftMax[i]<nums[i] && nums[i]<rightMin[i]){
                ansC+=2;
            }else if(nums[i - 1] < nums[i] && nums[i] < nums[i + 1]){
                ansC++;
            }
        }
        return ansC;
    }
}
```
['Java']