Rock Paper Scissors tournament problem
Anonymous User
456

Can anyone help me for the solution of below problem? I am trying to solve it using simulation of rounds and counting. Is there a DP involved here?


In a Rock Paper Scissors tournament, players stand in a line and each consecutive pair competes in a round. If there is an odd number of players, the last one automatically advances. They each choose a hand formation, either Rock(R), Paper(P), or Scissors(S). Outcomes are based on these rules:

  • Paper beats Rock (P > R)
  • Scissors beat Paper (S > P)
  • Rock beats Scissors (R > S)

Winners proceed to the next round while losers are eliminated. If there is a tie, both players are out.

A player, the person of interest (POI), wants to win while changing their hand formation as few times as possible. All other players must continue with their first choice. Determine the minimum number of changes the POI must make to win the tournament.

Example 1
Input: n = 3 players, poi = 2 play of interest, formations = "PS"
Output: 0
Explanation: The player of interest is at position 2 (0-based index).

  • Round 1
    • Players 0 and 1: Scissors beat Paper (player 1 advances)
    • poi advances to the second round (no challenger)
  • Round 2
    • poi and player 1: chooses Rock and wins

Since the POI never needs to change the hand formation, the answer is 0.

Example 2
Input: n = 4 players, poi = 1 player of interest, formations = "PRS"
Output: 1
Explanation: Players 0, 2 and 3 choose 'P', 'R' and 'S' respectively.

  • Round 1
    • poi chooses Scissors
    • players 0 and 1 (poi): poi chooses Scissors to beat Paper (poi advances)
    • players 2 and 3: Rock beats Sciossrs (player 2 advances)
  • Round 2
    • poi and player 2: poi chooses Paper and wins (1 change)

Constraints

  • 2 ≤ n ≤ 10^5
  • 0 ≤ poi < n
  • formations[i] is either 'R', 'P' or 'S' (0 ≤ i < n-1)
Comments (1)