All problems
Toeplitz Matrix
Problem
Build a Toeplitz matrix from its first row and first column. A Toeplitz matrix is constant along each diagonal.
Set T[i][j] = first_row[j - i] when j >= i, and T[i][j] = first_col[i - j] otherwise. Assume first_row[0] == first_col[0].
Hint
The first row fills diagonals going up-right; the first column fills diagonals going down-left.
Test cases
case 1
in: [[1,2,3],[1,4,5]]
expected: [[1,2,3],[4,1,2],[5,4,1]]
case 2
in: [[1,2],[1,3]]
expected: [[1,2],[3,1]]
case 3
in: [[7],[7]]
expected: [[7]]
case 4
in: [[1,2,3],[1,2,3]]
expected: [[1,2,3],[2,1,2],[3,2,1]]
Starter codePython
def toeplitz_matrix(first_row, first_col):
# Your code here
pass4 test cases · run your code against them in the editor