Easy C++ solution || Beginner-friendly approach with explanation || O(N) time complexity
Code\n\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> minRight(n, 0); // Vector to ma
# Code\n```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int n = nums.size();\n        vector<int> minRight(n, 0); // Vector to maintain the minimum value on the right side of an element\n        minRight[n - 1] = nums[n - 1];\n        for(int i = n - 2; i >= 2; i--){\n            minRight[i] = min(minRight[i + 1], nums[i]);           \n        }  \n        int maxLeft = nums[0], ans = 0;\n        for(int i = 1; i < n - 1; i++)\n        {\n            if(nums[i] > maxLeft && nums[i] < minRight[i + 1]) ?? Check for 1st condition\n                ans += 2;\n            else if(nums[i] > nums[i - 1] && nums[i] < nums[i + 1]) // If condition 1 is not followed, check for condition 2\n                ans += 1;\n            maxLeft = max(nums[i], maxLeft); // Update the maximum value in the left side of the element\n        }   \n        return ans;\n    }\n};\n```
['C++']