Java
Find the min[i]: Minimum Value from Right to i + 1\n2. For loop and keep track of Max value so far \n\nclass Solution {\n    public int sumOfBeauties(int[] nums
1. Find the min[i]: Minimum Value from Right to i + 1\n2. For loop and keep track of Max value so far \n```\nclass Solution {\n    public int sumOfBeauties(int[] nums) {\n        int n = nums.length;\n        int max = nums[0];\n        int[] min = new int[n];\n        min[n - 1] = nums[n - 1];\n        for (int i = n - 2; i >= 0; i--) {\n            min[i] = Math.min(min[i + 1], nums[i + 1]);\n        }\n        int res = 0;\n        for (int i = 1; i <= n - 2; i++) {\n            if (max < nums[i] && min[i] > nums[i]) {\n                res += 2;\n            } else if (nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) {\n                res += 1;\n            } \n            max = Math.max(nums[i], max);\n        }\n        return res;\n    }\n}\n```
[]