Integer Matrix Determinant

MediumMatrixMath

Description

Given an n x n matrix of integers (n ≤ 10), return its determinant as an integer. Use the fraction-free Bareiss algorithm so all intermediate values stay integral.

Examples

Input:matrix = [[1,2],[3,4]]
Output:-2
Explanation:

1*4 - 2*3 = -2.

Input:matrix = [[5]]
Output:5
Explanation:

1x1 determinant is the element.

Input:matrix = [[1,0,0],[0,1,0],[0,0,1]]
Output:1
Explanation:

Identity determinant is 1.

Constraints

  • 1 ≤ n ≤ 10
  • -100 ≤ matrix[i][j] ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!