Kotlin solution in 6 lines


  • 0
    E
    fun reconstructQueue(people: Array<Pair<Int,Int>>): Array<Pair<Int,Int>> {
        people.sortWith(compareBy({ -it.first }, { it.second }))
        val output = mutableListOf<Pair<Int,Int>>()
        people.forEach { output.add(it.second, it) }
        return output.toTypedArray()
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.