just a variant
Code\n\nclass Solution {\n    fun earliestAndLatest(n: Int, firstPlayer: Int, secondPlayer: Int): IntArray {\n        val res = intArrayOf(Int.MAX_VALUE, Int.MI
# Code\n```\nclass Solution {\n    fun earliestAndLatest(n: Int, firstPlayer: Int, secondPlayer: Int): IntArray {\n        val res = intArrayOf(Int.MAX_VALUE, Int.MIN_VALUE)\n\n        fun dfs(l: Int, r: Int, n: Int, rn: Int) {\n            if (l == r) {\n                res[0] = minOf(res[0], rn)\n                res[1] = maxOf(res[1], rn)\n            }\n            val (l,r) = if (l<r) l to r else r to l\n            (1..<l + 1).forEach { i ->\n                (l - i + 1..minOf(r, (n + 1) / 2) - i).forEach { j ->\n                    if (l + r - j - i <= n / 2) dfs(i, j, (n + 1) / 2, rn + 1) } }\n        }\n\n        dfs(firstPlayer, n - secondPlayer + 1, n, 1)\n        return res\n    }\n}\n```
['Kotlin']