Max (L->R) and Min(R->L)- Sliding Window
\nclass Solution {\n    public int sumOfBeauties(int[] nums) {\n        int n = nums.length;\n        int[] max = new int[nums.length];\n        int[] min = new
```\nclass Solution {\n    public int sumOfBeauties(int[] nums) {\n        int n = nums.length;\n        int[] max = new int[nums.length];\n        int[] min = new int[nums.length];\n        \n        int maxi = Integer.MIN_VALUE;\n        int mini = Integer.MAX_VALUE;\n        for(int i=0; i<n; i++) {\n            max[i] = Math.max(maxi,nums[i]);\n            maxi = max[i];\n            min[n-i-1] = Math.min(mini, nums[n-i-1]);\n            mini = min[n-i-1];\n        }\n        \n        int count = 0;\n        for(int i=1; i<n-1; i++) {\n            if(nums[i-1] < nums[i] && nums[i] < nums[i+1]) {\n                count++;\n                if(nums[i] < min[i+1] && nums[i] > max[i-1]) {\n                    count++;\n                }\n            }\n        }\n        \n        return count;\n    }\n}\n```
[]