C# O(n)
```\npublic class Solution {\n    public int SumOfBeauties(int[] nums) {\n        int res = 0;\n        int size = nums.Length;\n        \n        int[] minRigh
```\npublic class Solution {\n    public int SumOfBeauties(int[] nums) {\n        int res = 0;\n        int size = nums.Length;\n        \n        int[] minRight = new int[size];\n        minRight[size-1] = nums[size-1];\n        for(int i = size-2; i >= 0 ; i--)\n        {\n            minRight[i] = Math.Min(minRight[i+1],nums[i] );\n        }\n        int[] maxLeft = new int[size];\n        maxLeft[0] = nums[0];\n        for(int i = 1; i < size; i ++)\n        {\n            maxLeft[i] = Math.Max(maxLeft[i-1], nums[i]);\n        }\n        \n        int index= 1;\n        while(index < size-1)\n        {\n            if(maxLeft[index-1]<nums[index] && minRight[index+1]>nums[index])\n                res+=2;\n            else if(nums[index-1]<nums[index] && nums[index]<nums[index+1])\n                res+=1;\n            index++;\n        }\n       \n        \n        return res;\n    }\n}
[]