Python solution with O(n) time complexity and constant memory
Runtime: 1273 ms, faster than 70.00% of Python online submissions for Sum of Beauty in the Array.\nMemory Usage: 25.1 MB, less than 100.00% of Python online sub
* Runtime: 1273 ms, faster than 70.00% of Python online submissions for Sum of Beauty in the Array.\nMemory Usage: 25.1 MB, less than 100.00% of Python online submissions for Sum of Beauty in the Array.\n\nThis solution sweeps throught the array twice, first from left to right setting the elements to their negative if they fullfil the first part of the first condition.\nOn the second sweep, i check the second part of the first condition, if this is also true I sum 1. I sum 1 instead of 2 because i\'ll be checking the second condition next, which will be true if the first condition is true.\n\n```\nclass Solution(object):\n    def sumOfBeauties(self, nums):\n        big_left, small_right = nums[0], nums[-1]\n        \n        for i in range(1, len(nums)-1):\n            if big_left < nums[i]:\n                big_left = nums[i]\n                nums[i] = -nums[i]\n            \n        sum = 0\n        for i in range(len(nums)-2, 0, -1):\n            if nums[i] < 0:\n                nums[i] = -nums[i]\n                if small_right > nums[i]:\n                    sum += 1\n            if abs(nums[i - 1]) < nums[i] and nums[i] < nums[i + 1]:\n                sum += 1\n            small_right = min(small_right, nums[i])\n        return sum\n\t\t
[]