Visit every cell in row order and join the values.
Acceptance criteria
- 1.#out should show 1-2-3-4.
DSA Tutorial · Matrix and 2D Arrays
These 10 tasks go with the Matrix Traversal and Manipulation chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Grid problems are graph problems with implicit edges. Before any of that, though, you have to create the grid correctly — and the obvious way is wrong.” .
1.Walk row by rowexercise · easy · 10 min
Visit every cell in row order and join the values.
Passes when: #out should show 1-2-3-4.
2.Walk column by columnexercise · easy · 10 min · practice plan
Visit cells down each column and join the values.
Passes when: #out should show 1-3-2-4.
3.Transposeexercise · easy · 10 min · practice plan
Swap rows and columns, then join the first row.
Passes when: #out should show 1-3.
4.Count the neighboursexercise · easy · 10 min · practice plan
Count the in-bounds four-way neighbours of a corner cell.
Passes when: #out should show two neighbours.
5.Build a grid safelyexercise · medium · 10 min · practice plan
Create a two-row grid and confirm the rows are independent.
Passes when: #out should show rows independent.
6.Fix the row and column swappedbug fix · easy · 8 min
Indexing column first walks the grid the wrong way.
Passes when: #out should show 1-2-3-4.
7.Fix the rows sharing one arraybug fix · easy · 8 min · practice plan
fill with a literal stores the same row in every slot.
Passes when: #out should show rows independent.
8.Fix the transpose swapping twicebug fix · medium · 8 min · practice plan
Starting the inner loop at zero undoes every swap.
Passes when: #out should show 1-3.
9.Fix the missing bounds checkbug fix · easy · 8 min · practice plan
Counting every direction includes cells outside the grid.
Passes when: #out should show two neighbours.
10.Fix the column walk reading rowsbug fix · easy · 8 min · practice plan
Iterating rows in the outer loop gives row order, not column order.
Passes when: #out should show 1-3-2-4.
Between them these tasks cover Row and column order, Bounds checks and Rotation.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.