✅✅Faster || Easy To Understand || C++ Code
Time Complexity : O(N)\n\n Space Complexity : O(N)*\n\n\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        \n        int n = nums.s
* ***Time Complexity : O(N)***\n\n* ***Space Complexity : O(N)***\n\n```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        \n        int n = nums.size();\n        \n        // store the max. element till ith index from left side\n        \n        vector<int> left_max(n, 0);\n        \n        left_max[0] = nums[0];\n        \n        for(int i = 1; i < n; i++)\n        {\n            left_max[i] = max(left_max[i - 1], nums[i]);\n        }\n        \n        // store the min. element till ith index from right side\n        \n        vector<int> right_min(n, 0);\n        \n        right_min[n - 1] = nums[n - 1];\n        \n        for(int i = n - 2; i >= 0; i--)\n        {\n            right_min[i] = min(right_min[i + 1], nums[i]);\n        }\n        \n        // calculate the beauty on the basis of condition given\n        \n        int beauty_sum = 0;\n        \n        for(int i = 1; i <= n - 2; i++)\n        {\n            if(nums[i] > left_max[i - 1] && nums[i] < right_min[i + 1])\n            {\n                beauty_sum += 2;\n            }\n            else if(nums[i] > nums[i - 1] && nums[i] < nums[i + 1])\n            {\n                beauty_sum += 1;\n            }\n        }\n        \n        return beauty_sum;\n    }\n};\n```
['Array', 'C']