Worked example
// grid = {{1,2,3},{4,5,6},{7,8,9}}
row-major: 1 2 3 4 5 6 7 8 9
column-major: 1 4 7 2 5 8 3 6 9
Two more useful patterns. The main diagonal is where row equals column — g[i][i] gives 1 5 9. The anti-diagonal runs the other way: g[i][g.length - 1 - i] gives 3 5 7.
⚠️ And the classic mix-up: g.length is the number of rows, g[0].length the number of columns. Swapping them is the most common 2D bug.