C++ Simple and Easy Solution, Explained
Idea:\nWe need to know if the current number is smaller than all the elements ahead. \nSo first, we keep a minimum suffix array.\nThen, while iterating the arra
**Idea:**\nWe need to know if the current number is smaller than all the elements ahead. \nSo first, we keep a minimum suffix array.\nThen, while iterating the array, we keep a prefix maximum to know if the current element is greater than all the previous elements, and just check the options in the statement.\n\n**Time Complexity:** O(n)\n**Space Complexity:** O(n)\n```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int n = nums.size(), res = 0, prefix_max = nums[0];\n        vector<int> suffix(n, nums[n-1]);\n        \n        for (int i = n-2; i >= 0; i--) suffix[i] = min(suffix[i+1], nums[i]);\n        \n        for (int i = 1; i < n-1; i++) {\n            if (prefix_max < nums[i] && nums[i] < suffix[i+1]) res += 2;\n            else if (nums[i-1] < nums[i] && nums[i] < nums[i+1]) res++;\n            \n            prefix_max = max(prefix_max, nums[i]);\n        }\n        return res;\n    }\n};\n```\n**Like it? please upvote!**
['C']