Simple Hashmap Solution
class Solution {\npublic:\n    int sumOfBeauties(vector& nums) {\n     \n        mapmp,cp;\n        int n=nums.size();\n        int ans=0;\n        for(int i=0;
class Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n     \n        map<int,int>mp,cp;\n        int n=nums.size();\n        int ans=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            cp[nums[i]]++;\n        }\n           cp[nums[0]]--;\n        if(cp[nums[0]]==0)\n           cp.erase(nums[0]);\n           mp[nums[0]]++;\n        for(int i=1;i<n-1;i++)\n        {  \n             \n              cp[nums[i]]--;\n            if(cp[nums[i]]==0)\n             cp.erase(nums[i]);\n              auto j=*mp.rbegin();\n              auto y=*cp.begin();\n               if(y.first>nums[i] && j.first<nums[i])\n               {\n                      ans+=2;\n                \n               }\n            else if(nums[i]>nums[i-1] && nums[i]<nums[i+1])\n            {\n                ans+=1;\n            }\n             mp[nums[i]]++;\n            \n        }\n        return ans;\n        \n    }\n};\n//Time  Complexity-> Nlog(N)\n// Space Complexity->O(N)
[]