Python | Two Passes | O(n)
Code\n\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        n = len(nums)\n        d = [0]*n\n        d[-1] = nums[-1]\n        for i
# Code\n```\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        n = len(nums)\n        d = [0]*n\n        d[-1] = nums[-1]\n        for i in range(n-2,-1,-1):\n            d[i] = min(d[i+1], nums[i])\n        curmax = nums[0]\n        res = 0\n        for i in range(1,n-1):\n            if curmax < nums[i] < d[i+1]:\n                res += 2\n            elif nums[i-1] < nums[i] < nums[i+1]:\n                res += 1\n            curmax = max(curmax, nums[i])\n        return res\n        \n\n```
['Python3']