C++ Simple Clean & Concise   TC: O(n)   Explanation with code   ☑ ☑
The approcah is to know the max element in left part and min element in right part\nfor O(n^2) Solution use two loop inside one loop one traversing in left part
The approcah is to know the max element in left part and min element in right part\nfor O(n^2) Solution use two loop inside one loop one traversing in left part and one in right part searching for max and min element respectively *But it will result in TLE as the solution is O(n^2)\n\nThe O(n) Solution :\nin this solution we are going to create two array so that we can store min and max element to a specific index i. And now we good to go and our work simply complete in single loop.\nCheck the max array for index less then the i and min array for i+1 (i have stored min elements in other way you can store it in increasing order of index) ;\nUpvote if you like the solution\n```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int sum=0;\n        vector<int> minV,maxV;\n        int maximum=0;\n        int minimum=INT_MAX;\n        for(int i=0;i<nums.size();i++)\n        {\n            maximum=max(maximum,nums[i]);\n            maxV.push_back(maximum);\n        }\n        for(int i=nums.size()-1;i>=0;i--)\n        {\n              minimum=min(minimum,nums[i]);\n            minV.push_back(minimum);\n        }\n        for(int i=1;i<nums.size()-1;i++)\n        {\n           if((maxV[i-1]<nums[i] && minV[minV.size()-i-2]>nums[i]))\n              sum+=2;\n           else if(nums[i-1]<nums[i] && nums[i+1]>nums[i])\n               sum+=1;\n        }\n      return sum;  \n    }\n};\n```
['C']