✅[Python] Simple and Clean, beats 92.65%✅
Intuition\n Describe your first thoughts on how to solve this problem. \nTo keep the min and max value for the list.\n# Approach\n Describe your approach to sol
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo keep the min and max value for the list.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Case 1 (Increment +2)**\nPrecomputing the minimum and maximum value till ```i```th index.\nWe can maintain a MinArray and MaxArray and check if the current number is smaller or greater.\n\n**Case 2 (Increment +1)**\nThis can be checked directly while tranversing the list.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        n=len(nums)\n        ans=0\n        minArr=[0 for _ in range(n)]\n        maxArr=[999999 for _ in range(n)]\n        minArr[0]=nums[0]\n        maxArr[-1]=nums[-1]\n        for i in range(1,n):\n            minArr[i]=max(nums[i-1],minArr[i-1])\n        for i in range(n-2,-1,-1):\n            maxArr[i]=min(nums[i+1],maxArr[i+1])\n        for i in range(1,n-1):\n            if minArr[i]<nums[i]<maxArr[i]:\n                ans+=2\n            elif nums[i-1]<nums[i]<nums[i+1]:\n                ans+=1\n        return ans\n\n```
['Array', 'Suffix Array', 'Iterator', 'Python3']