Bird
Raised Fist0

Given a flexible NxN board and multiple players, what is the output of this pseudocode?

medium📝 Analysis Q5 of Q15
LLD - Design — Tic-Tac-Toe Game
Given a flexible NxN board and multiple players, what is the output of this pseudocode?
board_size = 3
players = ["A", "B", "C"]
turn = 5
current_player = players[(turn - 1) % len(players)]
print(current_player)
AA
BB
CC
DIndexError
Step-by-Step Solution
Solution:
  1. Step 1: Calculate index for current player

    Index = (turn - 1) % number of players = (5 - 1) % 3 = 4 % 3 = 1.
  2. Step 2: Find player at index 1

    players[1] = "B".
  3. Final Answer:

    B -> Option B
  4. Quick Check:

    Index calculation correct = player B [OK]
Quick Trick: Subtract 1 before modulo for zero-based indexing [OK]
Common Mistakes:
MISTAKES
  • Not subtracting 1 before modulo
  • Confusing player list indexing
  • Expecting IndexError due to modulo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes