FastPrepFind the Compromised Server
Problems/Find the Compromised Server

Find the Compromised Server

Shopify logoShopify● MediumINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The directional search rules match the screenshots at about 90%. The practice contract fixes the next probe at the center of the remaining search area.

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 <= 10000
  • 1 <= height <= 10000
  • 0 <= startX < width
  • 0 <= startY < height
  • 0 <= directions.length <= 30
  • Each 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.

More Shopify problems

  • Deterministic Secret Santa AssignmentPHONE SCREEN · Seen Oct 2026
  • Mars Rover Robot ControllerPHONE SCREEN · Seen Oct 2026
  • Choose Items for a BackpackOA · Seen May 2026
All Shopify interview questionsSee Shopify hiring insights
Saved
public int[][] planServerProbes(int width, int height, int startX, int startY, String[] directions) {
    // Write your code here.
}
Checking account…