JavaScript DFS
Relatively straightforward DFS. You can get away with a complete brute force if you want, though memoization will improve the runtime.\n\nYou probably also don\
Relatively straightforward DFS. You can get away with a complete brute force if you want, though memoization will improve the runtime.\n\nYou probably also don\'t need a bitmask, but since ```n < 32```, may as well.\n\nWe\'ll use DFS, moving from player to player until we\'ve gone halfway through the list, since that means we\'ve matched everyone up against each other. Then we remove the current player from available players if they lost, or remove their opponent if they won.\n\n```\nvar earliestAndLatest = function (n, firstPlayer, secondPlayer) {\n  let earliest = n;\n  let latest = 0;\n\n  const visited = new Set();\n\n  const findEarliestAndLatest = (remain, players, current, round) => {\n    if (visited.has(remain)) return;\n    \n    const player = players[current];\n    const opponent = players[players.length - current]; // since we\'re 1-indexed\n\n    if (player === firstPlayer && opponent === secondPlayer) {\n      earliest = Math.min(earliest, round);\n      latest = Math.max(latest, round);\n      return;\n    }\n\n    if (opponent <= player) {\n\t  // we\'ve gone halfway through the list, so everyone has been matched up\n\t  // go to the next round\n      const nextPlayers = players.filter((p) => remain & (1 << p));\n      findEarliestAndLatest(remain, nextPlayers, 1, round + 1);\n      return;\n    }\n\n    const remainIfPlayerWins = remain ^ (1 << opponent);\n    const remainIfOpponentWins = remain ^ (1 << player);\n    const next = current + 1;\n\n\t// it\'s possible both firstPlayer and secondPlayer are in the first half of the list\n    if (player === firstPlayer || player === secondPlayer) {\n      findEarliestAndLatest(remainIfPlayerWins, players, next, round);\n      return;\n    }\n    \n\t// it\'s possible both firstPlayer and secondPlayer are in the second half of the list\n    if (opponent === firstPlayer || opponent === secondPlayer) {\n      findEarliestAndLatest(remainIfOpponentWins, players, next, round);\n      return;\n    }\n\n    // neither player nor opponent are firstPlayer or secondPlayer\n    findEarliestAndLatest(remainIfPlayerWins, players, next, round);\n    findEarliestAndLatest(remainIfOpponentWins, players, next, round);\n    visited.add(remain);\n  }\n\n  const players = new Array(n + 1).fill(0).map((_, i) => i);\n  const ALL_PLAYERS_REMAIN = 2 ** (n + 1) - 1;\n  findEarliestAndLatest(ALL_PLAYERS_REMAIN, players, 1, 1);\n\n  return [earliest, latest]\n};\n```
['Bit Manipulation', 'Depth-First Search', 'JavaScript']