Squares of Sorted Array

I solved this problem in like, maybe 5 seconds haha.

class Solution {
    fun sortedSquares(A: IntArray): IntArray {
        return A.map {it * it}.sorted().toIntArray()
    }
}

Use map to go through each Int and just freakin square it and then sort then finally convert back to int array. Done.

Runtime: 320 ms, faster than 55.17% of Kotlin online submissions for Squares of a Sorted Array.
Memory Usage: 41.2 MB, less than 100.00% of Kotlin online submissions for Squares of a Sorted Array.
comments powered by Disqus