Join Nostr
2026-11-26 09:37:50 UTC

codementor on Nostr: Learn: Matrix What: a grid of rows and columns; m[row, col] reads one cell. Cost: ...

Learn: Matrix

What: a grid of rows and columns; m[row, col] reads one cell.
Cost: visiting every cell is O(rows × cols).
Use it when: data is naturally a grid: images, game boards, maps, seating plans, or a table of results in dynamic programming.

```csharp
int[,] grid = { { 1, 2 }, { 3, 4 } };
int sum = 0;
foreach (int x in grid) sum += x;
Console.WriteLine($"{grid.GetLength(0)}x{grid.GetLength(1)}, sum {sum}");
```

It prints 2x2, sum 10. Common interview moves: walk row by row, walk the diagonal, rotate, or spiral.

Read more: https://www.geeksforgeeks.org/dsa/matrix/

#tip · TIP-025