python3 precomputation
\n\n\n\n Case1: for each index in nums if every element before this is smaller and every element after this is bigger \nthan we have to increase count by 2\nfor
\n\n\n\n* **Case1**: for each index in nums if every element before this is smaller and every element after this is bigger \nthan we have to increase count by 2\nfor this can we can make two array which will store minimum and maximum till now for each index\n* **Case2**: simply compare with left and right neighbour ,if condition satisfies we will increase count by 1\n\n```\n\ndef sumOfBeauties(self, nums) :\n        N=len(nums)\n        \n        # for each index we have to check if all element before it is smaller than this\n        min_=[None for _ in range(N)]\n        mi_=float(\'-inf\')\n        for i in range(N):\n            min_[i]=mi_\n            mi_=max(nums[i],mi_)\n                \n        # for each index we have to check if all element after it is bigger than this       \n        max_=[None for _ in range(N)]\n        mx_=float(\'inf\')\n        for i in range(N-1,-1,-1):\n            max_[i]=mx_\n            mx_=min(mx_,nums[i])\n                \n        ans=0\n        for i in range(1,N-1):\n            if min_[i]<nums[i]<max_[i]:\n                ans+=2\n            elif nums[i-1]<nums[i]<nums[i+1]:\n                ans+=1\n        return ans\n```\n\t\t\n* **TC - O(N)**
['Python', 'Python3']