C++ | Easy to understand | Beats 100%
IntuitionApproachComplexity
Time complexity:O(n)

Space complexity:O(n)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:$$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:$$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int sumOfBeauties(vector<int>& nums) {
        int n = nums.size();
        vector<int> v(
            n); // To track min element from right subarray for each index

        int mini = INT_MAX;
        for (int i = n - 1; i >= 0; i--) {
            mini = min(mini, nums[i]);
            v[i] = mini;
        }

        int ans = 0, maxi = nums[0];
        for (int i = 1; i < n - 1; i++) {
            int x = nums[i];
            if (x > maxi && x < v[i + 1]) {
                ans += 2;
            } else if (x > nums[i - 1] && x < nums[i + 1]) {
                ans += 1;
            } 
            maxi = max(maxi, nums[i]);
        }
        return ans;
    }
};
```
['C++']