c++ o(n) o(n)
\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int n = nums.size();\n        vector<bool> dp(n,true);\n        int maxleft = n
```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int n = nums.size();\n        vector<bool> dp(n,true);\n        int maxleft = nums[0];\n        int minright = nums[n-1];\n        for(int i=1; i<n-1; i++)\n        {\n            if (nums[i]<=maxleft) \n                dp[i] = false;\n            if (nums[n-i-1]>=minright)\n                dp[n-i-1] = false;\n            maxleft = max(maxleft,nums[i]) ;\n            minright = min(minright,nums[n-i-1]) ;\n        }\n        int res = 0; \n        for(int i=1; i<n-1; i++)\n        {\n            if (dp[i])\n                res+=2;\n            else if (nums[i-1]<nums[i] && nums[i+1]>nums[i])\n                res+=1;\n        }\n        return res;\n    }\n};\n```
[]