Kotlin 2 pointer
Intuition\nSolved first by sorting reversed and then filtering with an {it > value} predicate, which results in TLE. This wasn\'t a great solution.\n\nTo remove
# Intuition\nSolved first by sorting reversed and then filtering with an {it > value} predicate, which results in TLE. This wasn\'t a great solution.\n\nTo remove filtering within the loop, figured I\'d use a lagging pointer for comparison\n\n# Approach\nStart a lagging pointer at 0, move if a "replacer" candidate is found\n\n# Complexity\n- Time complexity:\nO(nlogn) given sorting\n\n# Code\n```kotlin []\nclass Solution {\n\n    fun maximizeGreatness(nums: IntArray): Int {\n        val sorted = nums.sorted()\n        var swaps = 0\n        var pointer = 0\n        sorted.forEachIndexed { index, value ->\n            if (value > sorted[pointer]) {\n                swaps++\n                pointer++\n            }\n        }\n        return swaps\n    }\n}\n```
['Kotlin']