Bird
0
0

In a game with 5 players, if the current player index is 4, what will be the next player index after executing:

medium📝 Analysis Q5 of 15
LLD - Design — Tic-Tac-Toe Game
In a game with 5 players, if the current player index is 4, what will be the next player index after executing:
current_player = (current_player + 1) % 5
A1
B5
C4
D0
Step-by-Step Solution
Solution:
  1. Step 1: Calculate next index

    Adding 1 to 4 gives 5.
  2. Step 2: Apply modulo 5

    5 % 5 equals 0, so the index wraps to 0.
  3. Final Answer:

    0 -> Option D
  4. Quick Check:

    Modulo wraps index to zero after last player [OK]
Quick Trick: Modulo resets index to zero after last player [OK]
Common Mistakes:
MISTAKES
  • Expecting index to be 5 which is out of range
  • Not applying modulo operation
  • Confusing next player with previous player

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes