Java 0ms 100.00% simple recursion for all new positions of two players
In current round of n players, these two players with 1-based indexes p1 and p2 will compete if (p1 + p2 == n + 1). Otherwise, the game will enter next round wi
In current round of n players, these two players with 1-based indexes p1 and p2 will compete if (p1 + p2 == n + 1). Otherwise, the game will enter next round with (n+1)/2 players. Only the new positions (1-based indexes) of the two players matter in next round. We consider all possible such new positions based on their current positions and recursively get and merge into (min,max) as the final answer. \n\nDue to at most O(log(n)) rounds and the likelyhood p1 and p2 compete in earlier round, and the simplicity of the logic, the real runtime is 0ms and beats 100.00% Java submissions.\n\n```\n  public int[] earliestAndLatest(int n, int firstPlayer, int secondPlayer) {\n    int p1 = Math.min(firstPlayer, secondPlayer);\n    int p2 = Math.max(firstPlayer, secondPlayer);\n    if (p1 + p2 == n + 1) {\n      // p1 and p2 compete in the first round\n      return new int[] {1,1};\n    }\n    if (n == 3 || n == 4) {\n      // p1 and p2 must compete in the second round (only two rounds).\n      return new int[] {2,2};\n    }\n\n    // Flip to make p1 be more closer to left than p2 to right end for convenience\n    if (p1 - 1 > n - p2) {\n      int t = n + 1 - p1;\n      p1 = n + 1 - p2;\n      p2 = t;\n    }\n\n    int m = (n + 1) / 2;\n    int min = n;\n    int max = 1;\n    if (p2 * 2 <= n + 1) {\n      // p2 is in first half (n odd or even) or exact middle (n odd)\n      //   1  2  3  4  5  6  7  8  9 10 11 12 13 14\n      //   .  .  *  .  .  *  .  .  .  .  .  .  .  .\n      //         ^        ^\n      //         p1       p2\n\t  // Group A are players in front of p1\n\t  // Group B are players between p1 and p2\n      int a = p1 - 1;\n      int b = p2 - p1 - 1;\n      // i represents number of front players in A wins\n      // j represents number of front players in B wins\n      for (int i = 0; i <= a; i++) {\n        for (int j = 0; j <= b; j++) {\n          int[] ret = earliestAndLatest(m, i + 1, i + j + 2);\n          min = Math.min(min, 1 + ret[0]);\n          max = Math.max(max, 1 + ret[1]);\n        }\n      }\n    } else {\n      // p2 is in the later half (and has >= p1 distance to the end)\n      //    1  2  3  4  5  6  7  8  9 10 11 12 13 14\n      //    .  .  *  .  .  .  .  .  .  *  .  .  .  .\n      //          ^                    ^\n      //          p1   p4             p2    p3\n      //                ^--------------^\n      //          ^--------------------------^\n      int p4 = n + 1 - p2;\n      int a = p1 - 1;\n      int b = p4 - p1 - 1;\n\t  // Group C are players between p4 and p2, (c+1)/2 will advance to next round.\n      int c = p2 - p4 - 1;\n      for (int i = 0; i <= a; i++) {\n        for (int j = 0; j <= b; j++) {\n          int[] ret = earliestAndLatest(m, i + 1, i + j + 1 + (c+1)/2 + 1);\n          min = Math.min(min, 1 + ret[0]);\n          max = Math.max(max, 1 + ret[1]);\n        }\n      }\n    }\n    return new int[] {min, max};\n  }\n```
[]