C++ O(n) very simple (Using left and right Array)
```\nint sumOfBeauties(vector& nums) {\n        int n=nums.size();\n        \n        vector left(n);\n        vector right(n);\n        \n        left[0]=nums[
```\nint sumOfBeauties(vector<int>& nums) {\n        int n=nums.size();\n        \n        vector<int> left(n);\n        vector<int> right(n);\n        \n        left[0]=nums[0];\n        right[n-1]=nums[n-1];\n        \n        for(int i=1; i<n; i++)\n        {\n            left[i]=max(left[i-1],nums[i]);\n        }\n        for(int i=n-2; i>=0; i--)\n        {\n            right[i]=min(nums[i],right[i+1]);\n        }\n        \n        int count=0;\n        \n        for(int i=1; i<n-1; i++)\n        {            \n            if(left[i-1] < nums[i] && nums[i] < right[i+1])\n            {\n                count+=2;\n            }\n            else if(nums[i-1] < nums[i] && nums[i] < nums[i+1])\n            {\n                count++;\n            }\n        }\n        \n        return count;\n    }
[]