Kotlin - Treeset
\nclass ExamRoom(n: Int) {\n\n    val seated = TreeSet<Int>()\n    val capacity = n\n    \n    fun seat(): Int {\n        if(seated.isEmpty()){\n            sea
```\nclass ExamRoom(n: Int) {\n\n    val seated = TreeSet<Int>()\n    val capacity = n\n    \n    fun seat(): Int {\n        if(seated.isEmpty()){\n            seated.add(0)\n            return 0\n        }\n        \n        var seatNum = 0\n        \n        var maxDistance = seated.first()\n        var pre = -1\n        seated.forEach{\n            if(pre != -1){\n                val distance = (it-pre)/2\n                if(distance > maxDistance){\n                    maxDistance = distance\n                    seatNum = (it+pre)/2\n                }\n            }\n            pre = it\n        }\n        if(maxDistance < capacity-1-seated.last()){\n            seatNum = capacity-1\n        }\n        seated.add(seatNum)\n        \n        return seatNum\n    }\n\n    fun leave(p: Int) {\n        seated.remove(p)\n    }\n \n}\n```
[]