Matrices
Matrix problems are quite common and are relatively straightforward, just focus on understanding the techniques required
Runtime analysis
Corner cases
Techniques
Creating an empty M x N matrix
# Create zero matrix
# Inner array is the columns
# Outer array is the rows
zero_matrix = [[0] * len(matrix[0]) for _ in range(len(matrix))]
# Copy matrix
copied_matrix = [row[:] for row in matrix]Matrix transposition
Traversing common shapes
Treating matrix as flat array
Creating sub-grids
Last updated