# The Scoreboard Race

> Simulate rounds until someone hits the target.

Canonical URL: <https://datadriven.io/problems/the_scoreboard_race>

Domain: Python · Difficulty: medium · Seniority: L3

## Problem

Given num_players, a target score, and a sequential list of dice rolls, simulate round-robin: round 0 player 0, round 0 player 1, ..., then round 1 player 0, etc. Each roll adds to that player's running total. Return the list of final scores per player (same order as player index) after all rolls are consumed.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **simulation logic with round-robin turn management and termination conditions**. It checks whether candidates can implement a game loop with deterministic inputs, cycling through players and checking win conditions.

---

### Break down the requirements

#### Step 1: Initialize scores for all players

Create a list of zeros with one entry per player.

#### Step 2: Cycle through players using rolls

Each roll goes to the next player in round-robin order. Use modulo to cycle.

#### Step 3: Check the termination condition after each roll

After adding a roll to a player's score, check if any player has reached or exceeded the target.

#### Step 4: Return final scores

Return the score list when the game ends.

---

### The solution

**Round-robin simulation with deterministic rolls**

```python
def dice_race(num_players, target, rolls):
    scores = []
    for _ in range(num_players):
        scores.append(0)
    roll_idx = 0
    while True:
        player = roll_idx % num_players
        scores[player] += rolls[roll_idx]
        roll_idx += 1
        if scores[player] >= target:
            break
    return scores
```

> **Time and Space Complexity**
>
> **Time:** O(r) where r is the number of rolls consumed before someone wins.
> 
> **Space:** O(p) where p is the number of players.

> **Interviewers Watch For**
>
> Do you use `roll_idx % num_players` for round-robin? This is the clean way to cycle through players. Manual index tracking with reset is more error-prone.

> **Common Pitfall**
>
> Checking the win condition only at the end of a full round rather than after each individual roll. A player reaching the target mid-round should end the game immediately.

---

## Common follow-up questions

- What if the game continued until all players finished? _(Tests changing the termination condition and tracking who has finished.)_
- What if each player rolled multiple dice per turn? _(Tests summing multiple rolls per player per turn.)_
- How would you simulate this with random rolls? _(Tests using random.randint(1, 6) and ensuring reproducibility with random.seed.)_
- What if you needed to track the full history of each round? _(Tests appending round-by-round snapshots to a history list.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_scoreboard_race)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.