Problem · Matrix
Robo Data Sharing Direction
Learn this problemProblem 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:
Right:(row, col + 1).Left:(row, col - 1).Front:(row - 1, col).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) → StringExamples
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
rowsandcolsare positive.(startRow, startCol)is one of the four corners.1 <= row <= rowsand1 <= col <= cols.
More Arcesium problems
- Ordered Payload ReleaseONSITE INTERVIEW · Seen Jul 2026
- Decode Numeric StringONSITE INTERVIEW · Seen Jun 2026
- Tree Ancestor QueriesONSITE INTERVIEW · Seen Jun 2026
- City Infection NumberOA · Seen Jul 2025
- Minimum Tunnel Crossing TimeOA · Seen Jul 2025
- Product of Subset MaximaOA · Seen Jul 2025
- Reconstruct the Root StreamOA · Seen Jul 2025
- Add DigitsOA · Seen Aug 2023