Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-031

Matrix Power

Problem

Raise a square matrix A to the non-negative integer power k.

A^0 is the identity matrix of the same size. Use repeated multiplication for A^k.

Hint

Start from the identity and multiply by A k times.

Test cases

case 1
in: [[[2,0],[0,3]],3]
expected: [[8,0],[0,27]]
case 2
in: [[[1,1],[0,1]],5]
expected: [[1,5],[0,1]]
case 3
in: [[[1,2],[3,4]],0]
expected: [[1,0],[0,1]]
case 4
in: [[[0,1],[1,0]],2]
expected: [[1,0],[0,1]]
Starter codePython
def matrix_power(A, k):
    # Your code here
    pass

4 test cases · run your code against them in the editor