This is the problem the interviewer described to me verbally during the technical screen, done in a coderpad environment. They also gave an example along with it.
There is a game with multiple players. The road starts at position 0 and ends at position L. Each player has a starting position, and players can only move to the right, one unit per second.
There is a watcher, starting at position W, initially facing left. The watcher can only move in the direction it is facing, one unit per second.
The rules: if a player is being observed by the watcher (i.e., within its field of view), that player has to stay still. Otherwise, the player can move.
The system gives a set of timestamps indicating the moments when the watcher flips its facing direction.
Given a time range T, the question is: how many players can reach the endpoint L within time T?
Example:
T = 2
players = [1, 4], where p1 starts at position 1 and p2 starts at position 4
W = 3 (the watcher's starting position)
L = 5 (the endpoint)
flipDirection = [1] — the watcher only flips direction at timestamp 1
The output is 1, meaning only one player can reach the endpoint within T = 2.
Discussion
Loading comments…