Skip to main content

Overview

A matrix in data structures usually means a 2D array: a grid of values arranged in rows and columns. matrix

Movements

ActionRowColumn
Up-10
Down+10
Left0-1
Right0+1

Example

Suppose we are at Row 2, Col 3 and want to move two steps up.
[
  [0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0],
  [0, 0, 0, 1, 0, 0],
  [0, 0, 0, 0, 0, 0],
];
Apply the Up move (-1, 0) twice: subtract 1 from the row two times while keeping the column the same.
[
  [0, 0, 0, 1, 0, 0],
  [0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0],
];
The new position is Row 0, Col 3.

Build docs developers (and LLMs) love