Step 4 of 6
2D vectors
A vector of vectors makes a grid whose size is decided at runtime:
std::vector<std::vector<int>> grid(rows, std::vector<int>(cols, 0));
grid[r][c] = 5;
Your turn: write std::vector<std::vector<int>> transpose(const std::vector<std::vector<int>>& m) that swaps rows and columns. A 2x3 matrix becomes 3x2. You can assume every row has the same length and there's at least one row.
Previous: Insert and erase Next: string search and substrings