Simple solution using prefix and suffix sum || C++ || TC: 2*O(N) || SC: 2*O(N)
\nIntuition is: if the element at ith index > max of all the elements of left that means ith element is \ngreater than all the elements on left hand side,\n\nsi
```\nIntuition is: if the element at ith index > max of all the elements of left that means ith element is \ngreater than all the elements on left hand side,\n\nsimilarly if the ith index element is less than min of all the elements of right that implies\nith index element is smaller than all the elements on right hand side.\n\n\nclass Solution {\npublic:\n    void print(vector<int> &arr) {\n        int l = arr.size();\n        for(int i = 0; i < l; i++) {\n            cout<<arr[i]<<" ";\n        }\n        cout<<endl;\n    }\n    \n    int sumOfBeauties(vector<int>& nums) {\n        int l = nums.size();\n        vector<int> maxL(l, 0);\n        vector<int> minR(l, 1e9);\n        \n        maxL[0] = nums[0];\n        \n        minR[l-1] = nums[l-1];\n        \n        for(int i = 1; i < l; i++) {\n            maxL[i] = max(maxL[i-1], nums[i]);\n            \n            minR[l-1-i] = min(minR[l-1-i+1], nums[l-1-i]);\n            \n        }\n        \n        \n        // cout<<"maxL "<<endl;\n        // print(maxL);\n        \n        \n        \n        // cout<<"minR "<<endl;\n        // print(minR);\n        \n        int ans = 0;\n        \n        for(int i = 1; i < l-1; i++) {\n            if(maxL[i-1] < nums[i] && nums[i] < minR[i+1]) {\n                ans += 2;\n            }\n            else if(nums[i-1] < nums[i] && nums[i] < nums[i+1]) {\n                ans += 1;\n            }\n        }\n        \n        // cout<<"ans "<<ans<<endl;\n        return ans;\n    }\n};\n```
['C', 'Suffix Array']