Players Reaching the Boundary Under a Watcher
MediumSimulation ยท HRT
Count how many players reach the far end of a line. Players stand at integer positions players and each time step moves one position right, stopping once at or beyond boundary. A watcher stands at watcher and starts facing facing ("left" or "right").
At each time step from 1 to t, the watcher first reverses direction if that step appears in flips. Then every player moves, unless the watcher faces them: facing "right" blocks players at positions greater than watcher, and facing "left" blocks players at positions less than watcher. Return how many players are at or beyond boundary after step t.
Example 1
- Input:
- players = [0, 3, 4, 6], boundary = 6, watcher = 3, facing = "right", flips = [2, 5], t = 7
- Output:
- 3
- Explanation
- The players at 3, 4 and 6 end at the boundary. The player at 0 is only at position 4 after step 7.
Example 2
- Input:
- players = [1, 2, 5, 9], boundary = 8, watcher = 4, facing = "left", flips = [], t = 6
- Output:
- 2
Example 3
- Input:
- players = [4], boundary = 7, watcher = 4, facing = "right", flips = [], t = 3
- Output:
- 0
- Explanation
- The player at the watcher steps to 5 on step 1, then is blocked.
Constraints
0 <= players.length <= 1000000 <= players[i] <= 10^90 <= watcher <= boundary <= 10^90 <= flips.length <= 100000; the values are distinct, in any order, and between1and10^90 <= t <= 10^9