Problem · Matrix

Robo Data Sharing Direction

Learn this problem
EasyArcesium logoArcesiumFULLTIMEOA

Problem statement

Robots occupy every cell of a rows by cols matrix. Data starts at one corner, (startRow, startCol), using 1-based coordinates.

After a robot consumes the data, it passes the data to the first adjacent robot that has not consumed it, using this priority:

  1. Right: (row, col + 1).
  2. Left: (row, col - 1).
  3. Front: (row - 1, col).
  4. Back: (row + 1, col).

For the queried robot (row, col), return the direction in which it passes the data. Return Over if it is the final robot to consume the data.

Function

nextDataDirection(rows: int, cols: int, startRow: int, startCol: int, row: int, col: int) → String

Examples

Example 1

rows = 3cols = 3startRow = 1startCol = 1row = 3col = 3return = "Over"

Starting at the top-left corner produces a row-by-row snake traversal. Cell (3, 3) is last.

Example 2

rows = 2cols = 3startRow = 1startCol = 3row = 2col = 2return = "Right"

The first row is traversed right-to-left. After moving down, the second row is traversed left-to-right, so (2, 2) passes data right.

Constraints

  • rows and cols are positive.
  • (startRow, startCol) is one of the four corners.
  • 1 <= row <= rows and 1 <= col <= cols.

More Arcesium problems

drafts saved locally
public String nextDataDirection(int rows, int cols, int startRow, int startCol, int row, int col) {
  // Write your code here.
}
rows3
cols3
startRow1
startCol1
row3
col3
expected"Over"
checking account