[C++] Simple Solution | Logic Explained
During the contest I completely missed the point -> 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1. i.e. I did not c
During the contest I completely missed the point -> 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all **i < k <= nums.length - 1.** i.e. I did not check whether the current element is the minimum element among the elements on its right.\n```\nint sumOfBeauties(vector<int>& a) {\n        int n= a.size();\n        //This vector will store the minimum element on right side of current element, now the current element could also be the minimum when compared to right side of it, so min(nums[i], minRight[i+1])\n        vector<int> minRight(n,0);\n        minRight[n-1] = a[n-1];\n        \n        for(int i=n-2; i>=0; i--){\n            minRight[i] = min(a[i], minRight[i+1]);\n        }\n        //Now for beauty == 2, we need to check whether the current element is maximum element among the elements on its left, no need of seperate array for that, it can be maintained as we traverse through te array.\n        int maxLeft = a[0], res = 0;\n        for(int i=1; i<n-1; i++){\n            if(a[i] > maxLeft && a[i] < minRight[i+1]) res += 2;\n            else if(a[i] > a[i-1] && a[i] < a[i+1]) res += 1;\n            maxLeft = max(a[i], maxLeft);\n        }\n        \n        return res;\n    }\n```
['C', 'C++']