C++ | easy| with explanation
To calculate beauty for each index i (1 <= i <= nums.length - 2) \n1. For checking first condition we want max from 0 to i-1 and min  of i+1 to nums.length - 1.
To calculate beauty for each index i (1 <= i <= nums.length - 2) \n1. For checking first condition we want max from 0 to i-1 and min  of i+1 to nums.length - 1. To calculate this precompute min backwards. And we will find max from left as we iterate.\n2. If first condition is false then we calculate 2nd condition which is straight forward.\n**Time-O(n)\nSpace:-O(n)**\n\n```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n      int ans=0,size=nums.size(),left_max=nums[0];\n       vector<int>right(size,0);\n        int mini=nums[size-1];\n        for(int i=size-1;i>=0;i--)\n        {\n            right[i]=mini;\n            mini=min(mini,nums[i]);\n        }\n        for(int i=1;i<size-1;i++)\n        {\n            if(nums[i]>left_max && nums[i]<right[i])\n                ans+=2;\n             else if(nums[i]>nums[i-1] && nums[i]<nums[i+1])\n                 ans+=1;\n            left_max=max(left_max,nums[i]);\n        }\n        return ans;\n    }\n};\n```\nDo **UPVOTE** if it helps :)
['C']