Find the Compromised Server
Problem statement
A compromised server is hidden on a grid of width width and height height. The top-left cell is (0,0). Columns increase to the right and rows increase downward.
You start at (startX,startY). Each hint points from your current probe toward the same hidden server: U, UR, R, DR, D, DL, L, or UL. A pure vertical hint means the target has the same column; a pure horizontal hint means it has the same row.
For this exercise, assume the interactive hints are supplied in directions. Read them in order. The first hint is relative to the start, and each later hint is relative to the probe you returned for the previous hint. Keep every cell consistent with all hints so far. After each hint, probe the center of the remaining rectangle, choosing the smaller coordinate when a center lies between two cells.
Return the probes as a list of [x,y] pairs. Do not include the initial position. An empty hint list returns an empty list. The sequence may stop before the server is found.
Function
planServerProbes(width: int, height: int, startX: int, startY: int, directions: String[]) → int[][]Examples
Example 1
width = 5height = 5startX = 0startY = 0directions = ["DR","DR","DR"]return = [[2,2],[3,3],[4,4]]The first hint leaves columns and rows 1..4, whose chosen center is (2,2). The next hint leaves 3..4, giving (3,3). The last hint leaves only (4,4).
Example 2
width = 1height = 8startX = 0startY = 7directions = ["U","U","U"]return = [[0,3],[0,1],[0,0]]The column stays 0. The possible row ranges become 0..6, 0..2, and 0..0, so the probes are rows 3, 1, and 0.
Constraints
1 <= width <= 100001 <= height <= 100000 <= startX < width0 <= startY < height0 <= directions.length <= 30Each direction is U, UR, R, DR, D, DL, L, or UL.The directions are consistent with one fixed hidden target and the prescribed probes; no hint is given from the target itself.