[Kotlin] Clean & Short O(n) Solution
\nclass Solution {\n    fun sumOfBeauties(nums: IntArray): Int {\n        var leftMax = nums[0]\n        val rightMins = IntArray(nums.size).also { \n          
```\nclass Solution {\n    fun sumOfBeauties(nums: IntArray): Int {\n        var leftMax = nums[0]\n        val rightMins = IntArray(nums.size).also { \n            it[it.lastIndex] = nums[nums.lastIndex]\n            for (i in it.lastIndex - 1 downTo 2) {\n                it[i] = minOf(it[i + 1], nums[i])\n            }\n        }\n        return (1 until nums.lastIndex).fold(0) { acc, index ->\n            when {\n                nums[index] > leftMax && nums[index] < rightMins[index + 1] -> acc + 2\n                nums[index] > nums[index - 1] && nums[index] < nums[index + 1] -> acc + 1\n                else -> acc\n            }.also {\n                leftMax = maxOf(leftMax, nums[index])\n            }\n        }\n    }\n}\n```
['Kotlin']