Count players reaching end with moving watchers
Count Players Reaching End with Moving Watchers
You are given a 1D line of L cells indexed 0 to L-1. The target end cell is L-1.
There are W watchers and P players, each with initial integer positions.
A time horizon T is given, representing the number of unit-time steps.
An unsorted list flipTimes contains integer timestamps. At each timestamp t in flipTimes, all watchers reverse their direction.
Movement Model (Discrete Time):
- Time steps are
t = 0, 1, ..., T-1. - Each watcher has a facing direction (
LEFTorRIGHT). All watchers start facingLEFTat time 0. - At the start of each step
t, iftis inflipTimes, all watchers reverse direction. - Watching Rule: At step
t, a watcher at positionx:- If facing
LEFT, watches all cells< x. - If facing
RIGHT, watches all cells> x. A player is considered watched if at least one watcher watches the player's current cell.
- If facing
- Player Move: During step
t, each player attempts to move one cell to the right (fromptomin(p+1, L-1)). However, if the player is watched at the start of the step, the player cannot move and stays in place. - Watcher Move: After all players have attempted to move, each watcher moves one cell in its facing direction:
LEFT:x = max(x-1, 0)RIGHT:x = min(x+1, L-1)
Task:
After performing exactly T steps, return the count of players that are at cell L-1.
Notes/Clarifications:
- Multiple players and watchers may occupy the same cell.
flipTimesmay contain duplicates and is not sorted.
Constraints:
1 <= L <= 2e50 <= W, P <= 2e50 <= T <= 2e50 <= flipTimes[i] <= T-1
AI interview prep
Core dilemma
Simulating the state of numerous independent entities (watchers and players) over a large time horizon, while efficiently determining player visibility and movement constraints.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Count players reaching end with moving watchers
Count Players Reaching End with Moving Watchers
You are given a 1D line of L cells indexed 0 to L-1. The target end cell is L-1.
There are W watchers and P players, each with initial integer positions.
A time horizon T is given, representing the number of unit-time steps.
An unsorted list flipTimes contains integer timestamps. At each timestamp t in flipTimes, all watchers reverse their direction.
Movement Model (Discrete Time):
- Time steps are
t = 0, 1, ..., T-1. - Each watcher has a facing direction (
LEFTorRIGHT). All watchers start facingLEFTat time 0. - At the start of each step
t, iftis inflipTimes, all watchers reverse direction. - Watching Rule: At step
t, a watcher at positionx:- If facing
LEFT, watches all cells< x. - If facing
RIGHT, watches all cells> x. A player is considered watched if at least one watcher watches the player's current cell.
- If facing
- Player Move: During step
t, each player attempts to move one cell to the right (fromptomin(p+1, L-1)). However, if the player is watched at the start of the step, the player cannot move and stays in place. - Watcher Move: After all players have attempted to move, each watcher moves one cell in its facing direction:
LEFT:x = max(x-1, 0)RIGHT:x = min(x+1, L-1)
Task:
After performing exactly T steps, return the count of players that are at cell L-1.
Notes/Clarifications:
- Multiple players and watchers may occupy the same cell.
flipTimesmay contain duplicates and is not sorted.
Constraints:
1 <= L <= 2e50 <= W, P <= 2e50 <= T <= 2e50 <= flipTimes[i] <= T-1