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
Published at
2026-11-26 09:37:50 UTCEvent JSON
{
"id": "c28127e79bdcfe72f59e2dfe2e8455340095ede9052ebb34f41baeeffbe0b6e7",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1795685870,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Matrix\n\nWhat: a grid of rows and columns; m[row, col] reads one cell.\nCost: visiting every cell is O(rows × cols).\nUse it when: data is naturally a grid: images, game boards, maps, seating plans, or a table of results in dynamic programming.\n\n```csharp\nint[,] grid = { { 1, 2 }, { 3, 4 } };\nint sum = 0;\nforeach (int x in grid) sum += x;\nConsole.WriteLine($\"{grid.GetLength(0)}x{grid.GetLength(1)}, sum {sum}\");\n```\n\nIt prints 2x2, sum 10. Common interview moves: walk row by row, walk the diagonal, rotate, or spiral.\n\nRead more: https://www.geeksforgeeks.org/dsa/matrix/\n\n#tip · TIP-025",
"sig": "97b655df58bdd40cf6585b9c0afde42dd4f8135e6bad6b58c7578e8e3098b252acf5a294b6952b66bfb5852282c718b42cd143cec80c312f1fe25068c00b730f"
}