Easy C++ O(N) solution  || commented
\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        \n        //for case 1\n        //get the max for every element to the left and
```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        \n        //for case 1\n        //get the max for every element to the left and the min of every element to the right\n        //if max<arr[i]<min\n        //beauty for arr[i] becomes 2\n        //else check for either case 2 or case 3\n        \n        int n=nums.size();\n        vector<int> right(n);\n        int mini=nums[n-1];\n        for(int i=n-2;i>0;i--)\n        {\n            right[i]=mini;\n            mini=min(mini,nums[i]);\n        }\n        int maxi=nums[0];\n        int sum=0;\n        for(int i=1;i<n-1;i++)\n        {\n            if(maxi<nums[i] && nums[i]<right[i])\n            {\n                sum+=2;\n            }\n            else if(nums[i-1]<nums[i] && nums[i]<nums[i+1])\n            {\n                sum+=1;\n            }\n            maxi=max(maxi,nums[i]);\n        }\n        return sum;\n    }\n};\n```\n**Upvote if this helps you**
['C']