[C++] Clean & concise solution with detailed explaination !
Solution\nTo check  if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1 in O(1) we will build two arrays : max and min. \nma
* **Solution**\nTo check  if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1 in O(1) we will build two arrays : max and min. \nmax[i] = max value from 0 to i\nmin[i] = min value from i to n-1\nTherefore when we calculate the beauty of the nums[i] we can easily check\n if (nums[i]>max[i-1] && nums[i]<min[i+1]) then we add 2 to the result\n else if (nums[i]>nums[i-1] && nums[i]<nums[i+1]) then we add 1 to the result.\n \n* **Time Complexity**\nWe just go through the nums array so the time complexity is **O(n)**.\n\n* **Space Complexity**\nBecause we just use two array min and max to store min and max value so the space complexity is **O(n)**.\n\n* **Source Code**\n\n```\nclass Solution {\npublic:\n    int sumOfBeauties(vector<int>& nums) {\n        int n = nums.size();\n        int max[n];\n        int min[n];\n        \n        //max[i] = max value from 0 to i\n        //min[i] = min value from i to n-1\n        \n        max[0] = nums[0];\n        min[n-1] = nums[n-1];\n        \n        //build max array\n        for (int i=1;i<n;++i) {\n            if (nums[i]>max[i-1]) max[i]=nums[i];\n            else max[i] = max[i-1];\n        } \n        \n        //build min array\n        for (int i=n-2;i>=0;--i) {\n            if (nums[i]<min[i+1]) min[i]=nums[i];\n            else min[i] = min[i+1];\n        }\n        \n        int res = 0;\n        \n        //calculate the result\n        for (int i=1;i<n-1;++i) {\n            if (nums[i]>max[i-1] && nums[i]<min[i+1]) res +=2 ;\n            else if (nums[i]>nums[i-1] && nums[i]<nums[i+1]) ++res;\n        }\n        return res;\n    }\n};\n```
[]