O(n) simple solution c++ || just maintain min and max ||
\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        vector<int> left_max(nums.size());\n        vector<int> right_min(nums.size());
```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        vector<int> left_max(nums.size());\n        vector<int> right_min(nums.size());\n\t\t\n        int x = nums[0];\n        left_max[0]=x;\n        for(int i=1;i<nums.size();i++){\n            x = max(x,nums[i-1]);\n            left_max[i]=x;\n        }\n\t\t\n        x = nums[nums.size()-1];\n        right_min[nums.size()-1]=x;\n        for(int i=nums.size()-2;i>=0;i--){\n            x = min(x,nums[i+1]);\n            right_min[i]=x;\n        }\n\t\t\n        int ans = 0;\n        for(int i=1;i<nums.size()-1;i++){\n            if(left_max[i]<nums[i] && right_min[i]>nums[i]){\n                ans+=2;\n            }\n            else if(nums[i]>nums[i-1] && nums[i]<nums[i+1]){\n                ans+=1;\n            }\n        }\n\t\t\n        return ans;\n    }\n};\n```
[]