python | Prefix + Suffix | Easy to understand
\nclass Solution:\n    """\n    approach: \n    create two arrays prefix and suffix array\n    prefix[i] records the maximum value in range (0, i - 1) inclusive
```\nclass Solution:\n    """\n    approach: \n    create two arrays prefix and suffix array\n    prefix[i] records the maximum value in range (0, i - 1) inclusive.\n    suffix[i] records the minimum value in range (i + 1, n - 1) inclusive.\n    """\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        prefix = [float(\'-inf\') for _ in range(len(nums))]\n        suffix = [float(\'inf\') for _ in range(len(nums))]\n        for i in range(1, len(nums)):\n            prefix[i] = max(nums[i-1], prefix[i-1])\n        for i in range(len(nums)-2, -1, -1):\n            suffix[i] = min(nums[i+1], suffix[i+1])\n        pts = 0\n        for i in range(1, len(nums)-1):\n            if prefix[i] < nums[i] < suffix[i]:\n                pts += 2\n            elif nums[i-1] < nums[i] < nums[i+1]:\n                pts += 1\n        return pts\n```
['Python']