Given a square matrix of size N x N. The task is to find the determinant of this matrix.
Example 1:
Input:
N = 4
matrix[][] = {{1, 0, 2, -1},
              {3, 0, 0, 5},
              {2, 1, 4, -3},
              {1, 0, 5, 0}}
Output: 30
Explanation:
Determinant of the given matrix is 30.
Example 2:
Input:
N = 3
matrix[][] = {{1, 2, 3},
              {4, 5, 6},
              {7, 10, 9}}
Output: 12
Explanation:
Determinant of the given matrix is 12.
Your Task:
You don't need to read input or print anything. Complete the function determinantOfMatrix() that takes matrix and its size n as input parameters and returns the determinant of the matrix.
Expected Time Complexity: O(N^{4})
Expected Auxiliary Space: O(N^{2})
Constraints:
1 <= N <= 8
-10 <= mat[i][j] <= 10

Difficulty: EASY
Tags: Matrices

Data structures
Skill types: Data structures
Expected Time Complexity: O(N^{4})
Expected Auxiliary Space: O(N^{2})

Starter code:

#User function Template for python3

class Soltuion:
    
    #Function for finding determinant of matrix.
    def determinantOfMatrix(self,matrix,n):
        # code here 

Solutions:
class Solution:

	def determinantOfMatrix(self, a, n):
		if n == 1:
			return a[0][0]
		elif n == 2:
			return a[0][0] * a[1][1] - a[1][0] * a[0][1]
		else:
			ans = 0
			for col in range(n):
				small = []
				for i in range(1, n):
					dem = []
					for j in range(n):
						if j == col:
							continue
						dem.append(a[i][j])
					small.append(dem)
				if col % 2 == 0:
					ans += a[0][col] * self.determinantOfMatrix(small, n - 1)
				else:
					ans -= a[0][col] * self.determinantOfMatrix(small, n - 1)
			return ans


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		det = 0
		sign = 1
		for i in range(n):
			new_mat = []
			for y in range(n - 1):
				new_mat.append([])
				for x in range(n):
					if x != i:
						new_mat[y].append(matrix[y + 1][x])
			self.determinantOfMatrix(new_mat, n - 1)
			det += sign * matrix[0][i] * self.determinantOfMatrix(new_mat, n - 1)
			sign *= -1
		return det


import numpy as np

def determinant(mat):
	det = np.linalg.det(mat)
	return round(det)

class Solution:

	def determinantOfMatrix(self, matrix, n):
		return int(determinant(matrix))


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if len(matrix) == 1:
			return matrix[0][0]
		if len(matrix) == 2:
			return matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]
		currentCol = ans = 0
		while currentCol < len(matrix[0]):
			minor = [[0] * 0] * 0
			for i in range(len(matrix)):
				temp = []
				for j in range(len(matrix[0])):
					if i != 0 and j != currentCol:
						temp.append(matrix[i][j])
				if len(temp) > 0:
					minor.append(temp)
			ans = ans + matrix[0][currentCol] * (-1) ** currentCol * self.determinantOfMatrix(minor, len(minor))
			currentCol += 1
		return ans


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		elif n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		res = 0
		for i in range(len(matrix[0])):
			smallerMatrix = []
			for j in range(1, len(matrix)):
				col = []
				for k in range(len(matrix[0])):
					if k == i:
						continue
					col.append(matrix[j][k])
				smallerMatrix.append(col)
			if i % 2 == 0:
				res += matrix[0][i] * self.determinantOfMatrix(smallerMatrix, n - 1)
			else:
				res -= matrix[0][i] * self.determinantOfMatrix(smallerMatrix, n - 1)
		return res


import numpy as np
import math

class Solution:

	def determinantOfMatrix(self, matrix, n):
		det = np.linalg.det(matrix)
		return int(round(det))


import numpy as np

class Solution:

	def determinantOfMatrix(self, matrix, n):
		ans = str(np.linalg.det(matrix))
		s = ''
		for d in ans:
			if d == '.':
				break
			s += d
		return int(s)


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		det = 0
		for i in range(n):
			submatrix = [[0 for _ in range(n - 1)] for _ in range(n - 1)]
			for x in range(1, n):
				j = 0
				for y in range(n):
					if y == i:
						continue
					submatrix[x - 1][j] = matrix[x][y]
					j += 1
			det += matrix[0][i] * self.determinantOfMatrix(submatrix, n - 1) * (-1) ** i
		return det


class Solution:

	def determinantOfMatrix(self, mat, n):
		temp = [0] * n
		total = 1
		det = 1
		for i in range(0, n):
			index = i
			while index < n and mat[index][i] == 0:
				index += 1
			if index == n:
				continue
			if index != i:
				for j in range(0, n):
					(mat[index][j], mat[i][j]) = (mat[i][j], mat[index][j])
				det = det * int(pow(-1, index - i))
			for j in range(0, n):
				temp[j] = mat[i][j]
			for j in range(i + 1, n):
				num1 = temp[i]
				num2 = mat[j][i]
				for k in range(0, n):
					mat[j][k] = num1 * mat[j][k] - num2 * temp[k]
				total = total * num1
		for i in range(0, n):
			det = det * mat[i][i]
		return int(det / total)


class Solution:

	def getCofactor(self, matrix, i, j):
		return [row[:j] + row[j + 1:] for row in matrix[:i] + matrix[i + 1:]]

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		if n == 2:
			value = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
			return value
		else:
			s = 0
			for current_col in range(n):
				sign = (-1) ** current_col
				sub_matrix = self.getCofactor(matrix, 0, current_col)
				sub_det = self.determinantOfMatrix(sub_matrix, n - 1)
				s += sign * matrix[0][current_col] * sub_det
			return s


class Solution:

	def determinantOfMatrix(self, matrix, n):
		det = 0
		if n == 1:
			return matrix[0][0]
		if n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]
		for i in range(n):
			temp = []
			for row in range(1, n):
				p = []
				for col in range(n):
					if col == i:
						continue
					else:
						p.append(matrix[row][col])
				temp.append(p)
			if i % 2 == 1:
				det = det - matrix[0][i] * Solution.determinantOfMatrix(self, temp, n - 1)
			else:
				det = det + matrix[0][i] * Solution.determinantOfMatrix(self, temp, n - 1)
		return det


class Solution:

	def smallermatrix(self, matrix, row, col):
		from copy import deepcopy
		arr = deepcopy(matrix)
		arr.remove(matrix[row])
		for row in arr:
			row.pop(col)
		return arr

	def sol(self, matrix):
		n = len(matrix)
		if n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		ans = 0
		for i in range(n):
			total = (-1) ** i * matrix[0][i] * self.sol(self.smallermatrix(matrix, 0, i))
			ans += total
		return ans

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		ans = self.sol(matrix)
		return ans


from numpy import *

class Solution:

	def determinantOfMatrix(self, matrix, n):
		return int(round(linalg.det(matrix)))


class Solution:

	def submatrix(self, m, r, c):
		rows = len(m)
		columns = len(m[0])
		sm = []
		for i in range(rows):
			sm.append([])
			for j in range(columns):
				sm[i].append(m[i][j])
		sm = sm[1:]
		for i in range(len(sm)):
			sm[i] = sm[i][:c] + sm[i][c + 1:]
		return sm

	def determinant(self, m):
		rows = len(m)
		columns = len(m[0])
		if rows == 1 and columns == 1:
			return m[0][0]
		else:
			c = 1
			result = 0
			for i in range(columns):
				sm = self.submatrix(m, 0, i)
				result += c * m[0][i] * self.determinant(sm)
				c *= -1
			return result

	def determinantOfMatrix(self, matrix, n):
		return self.determinant(matrix)


class Solution:

	def getCofactor(self, matrix, temp, p, q, n):
		(i, j) = (0, 0)
		for row in range(n):
			for col in range(n):
				if row != p and col != q:
					temp[i][j] = matrix[row][col]
					j += 1
					if j == n - 1:
						j = 0
						i += 1

	def determinantOfMatrix(self, matrix, n):
		d = 0
		if n == 1:
			return matrix[0][0]
		temp = [[0 for i in range(n)] for i in range(n)]
		sign = 1
		for i in range(n):
			self.getCofactor(matrix, temp, 0, i, n)
			d += sign * matrix[0][i] * self.determinantOfMatrix(temp, n - 1)
			sign = -sign
		return d


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		if n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		total = 0
		for i in range(n):
			B = matrix.copy()
			B = B[1:]
			for j in range(n - 1):
				B[j] = B[j][0:i] + B[j][i + 1:]
			sign = (-1) ** (i % 2)
			sub_det = self.determinantOfMatrix(B, n - 1)
			total += matrix[0][i] * sign * sub_det
		return total


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		if n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		det = 0
		for col in range(n):
			if col % 2 == 0:
				det += matrix[0][col] * self.determinantOfMatrix(self.getTheMat(matrix, n, 0, col), n - 1)
			else:
				det -= matrix[0][col] * self.determinantOfMatrix(self.getTheMat(matrix, n, 0, col), n - 1)
		return det

	def getTheMat(self, matrix, n, x, y):
		mat = []
		for i in range(n):
			cur_mat = []
			for j in range(n):
				if i != x and j != y:
					cur_mat.append(matrix[i][j])
			if cur_mat != []:
				mat.append(cur_mat)
		return mat


import numpy as np

class Solution:

	def determinantOfMatrix(self, matrix, n):
		ans = np.linalg.det(matrix)
		a1 = round(ans)
		return int(a1)


class Solution:

	def cofactorMatrix(self, matrix, r, c):
		return [row[:c] + row[c + 1:] for row in matrix[:r] + matrix[r + 1:]]

	def determinantOfMatrix(self, matrix, n):
		if len(matrix) == 1:
			return matrix[0][0]
		if len(matrix) == 2:
			v = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
			return v
		sum = 0
		for curr_col in range(len(matrix)):
			sign = (-1) ** curr_col
			sub_det = self.determinantOfMatrix(self.cofactorMatrix(matrix, 0, curr_col), n)
			sum += sign * matrix[0][curr_col] * sub_det
		return sum


import numpy as np

class Solution:

	def determinantOfMatrix(self, arr, n):
		det = str(np.linalg.det(arr))
		l = len(det)
		return det[:l - 2]


class Solution:

	def cofac(self, m, j):
		return [row[:j] + row[j + 1:] for row in m[1:]]

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		if len(matrix) == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		s = 0
		for i in range(len(matrix)):
			sig = (-1) ** i
			sub_mat = self.cofac(matrix, i)
			g = self.determinantOfMatrix(sub_mat, len(sub_mat))
			s += sig * g * matrix[0][i]
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		values = list(map(int, input().strip().split()))
		k = 0
		matrix = []
		for i in range(n):
			row = []
			for j in range(n):
				row.append(values[k])
				k += 1
			matrix.append(row)
		obj = Solution()
		print(obj.determinantOfMatrix(matrix, n))


import numpy as np

class Solution:

	def determinantOfMatrix(self, matrix, n):
		m = 0
		m = round(np.linalg.det(matrix))
		return int(m)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		values = list(map(int, input().strip().split()))
		k = 0
		matrix = []
		for i in range(n):
			row = []
			for j in range(n):
				row.append(values[k])
				k += 1
			matrix.append(row)
		obj = Solution()
		print(obj.determinantOfMatrix(matrix, n))


class Solution:

	def determinantOfMatrix(self, matrix, n):
		import copy
		det = 0
		if n == 1:
			return matrix[0][0]
		if n == 2:
			det = matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1]
			return det
		else:
			for i in range(n):
				dup = copy.deepcopy(matrix)
				dup.pop(0)
				for j in dup:
					j.pop(i)
				l = len(dup)
				p = (-1) ** i * matrix[0][i] * self.determinantOfMatrix(dup, l)
				det += p
		return det
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		values = list(map(int, input().strip().split()))
		k = 0
		matrix = []
		for i in range(n):
			row = []
			for j in range(n):
				row.append(values[k])
				k += 1
			matrix.append(row)
		obj = Solution()
		print(obj.determinantOfMatrix(matrix, n))


class Solution:

	def cofactor(self, mat, i, j):
		ret = [row[:j] + row[j + 1:] for row in mat[:i] + mat[i + 1:]]
		return ret

	def determinantOfMatrix(self, mat, n):
		if n == 1:
			return mat[0][0]
		if n == 2:
			return mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]
		sum = 0
		for column in range(n):
			sign = (-1) ** column
			ret = self.determinantOfMatrix(self.cofactor(mat, 0, column), n - 1)
			sum += sign * ret * mat[0][column]
		return sum
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		values = list(map(int, input().strip().split()))
		k = 0
		matrix = []
		for i in range(n):
			row = []
			for j in range(n):
				row.append(values[k])
				k += 1
			matrix.append(row)
		obj = Solution()
		print(obj.determinantOfMatrix(matrix, n))


import numpy as np

class Solution:

	def determinantOfMatrix(self, matrix, n):
		return self.solve(np.asarray(matrix), n)

	def solve(self, matrix, size):
		if size == 1:
			return matrix[0, 0]
		if size == 2:
			return matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0]
		res = 0
		for i in range(size):
			sign = (-1) ** i
			submatrix = np.concatenate((matrix[1:size, 0:i], matrix[1:size, i + 1:size]), axis=1)
			res += sign * matrix[0, i] * self.solve(submatrix, size - 1)
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		values = list(map(int, input().strip().split()))
		k = 0
		matrix = []
		for i in range(n):
			row = []
			for j in range(n):
				row.append(values[k])
				k += 1
			matrix.append(row)
		obj = Solution()
		print(obj.determinantOfMatrix(matrix, n))


class Solution:

	def getCofactor(self, matrix, temp, p, q, n):
		(i, j) = (0, 0)
		for row in range(n):
			for col in range(n):
				if row != p and col != q:
					temp[i][j] = matrix[row][col]
					j += 1
					if j == n - 1:
						j = 0
						i += 1

	def determinantOfMatrix(self, matrix, n):
		d = 0
		if n == 1:
			return matrix[0][0]
		temp = [[0 for i in range(n)] for i in range(n)]
		sign = 1
		for i in range(n):
			self.getCofactor(matrix, temp, 0, i, n)
			d += sign * matrix[0][i] * self.determinantOfMatrix(temp, n - 1)
			sign = -sign
		return d
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		n = int(input())
		values = list(map(int, input().strip().split()))
		k = 0
		matrix = []
		for i in range(n):
			row = []
			for j in range(n):
				row.append(values[k])
				k += 1
			matrix.append(row)
		obj = Solution()
		print(obj.determinantOfMatrix(matrix, n))


import numpy

class Solution:

	def determinantOfMatrix(self, A, n):
		return int(round(numpy.linalg.det(A)))


class Solution:

	def determinantOfMatrix(self, matrix, n):

		def cofactor(arr, temp, i, j, n):
			s = 0
			t = 0
			for r in range(n):
				for c in range(n):
					if r != i and c != j:
						temp[s][t] = arr[r][c]
						t += 1
					if t == n - 1:
						t = 0
						s += 1
			return temp
		if n == 1:
			return matrix[0][0]
		temp = [[float('inf') for _ in range(n)] for _ in range(n)]
		sgn = 1
		det = 0
		for i in range(n):
			C = cofactor(matrix, temp, 0, i, n)
			det += matrix[0][i] * sgn * self.determinantOfMatrix(C, n - 1)
			sgn = -sgn
		return det


class Solution:

	def determinantMaker(self, a, m):
		b = []
		n = len(a)
		for i in range(1, n, 1):
			c = []
			for j in range(n):
				if j == m:
					continue
				else:
					c.append(a[i][j])
			b.append(c)
		return b

	def determinantOfMatrix(self, a, n):
		n = len(a)
		if n == 1:
			return a[0][0]
		elif n == 2:
			return a[0][0] * a[1][1] - a[1][0] * a[0][1]
		else:
			sign = 1
			ans = 0
			for i in range(n):
				temp = 0
				b = self.determinantMaker(a, i)
				m = len(b)
				temp = sign * a[0][i] * self.determinantOfMatrix(b, m)
				ans += temp
				sign *= -1
			return ans


class Solution:

	def determinantOfMatrix(self, matrix, n):

		def getSubmetrix(matrix, coordinations):
			(row, colomn) = coordinations
			newmatrxi = []
			for i in range(len(matrix)):
				if i == row - 1:
					continue
				newrow = []
				for j in range(len(matrix[0])):
					if j == colomn - 1:
						continue
					newrow.append(matrix[i][j])
				newmatrxi.append(newrow)
			return newmatrxi

		def determinant(matrix):
			if len(matrix) == 2:
				det = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
			elif len(matrix) > 2:
				det = 0
				for i in range(len(matrix)):
					submat = getSubmetrix(matrix, (1, i + 1))
					det += (-1) ** (i + 2) * determinant(submat) * matrix[0][i]
			else:
				return matrix[0][0]
			return det
		return determinant(matrix)


def getTruncatedMatrix(matrix, n, i, j):
	res = []
	for row in range(n):
		arr = []
		for col in range(n):
			if col != j:
				arr.append(matrix[row][col])
		if row != i:
			res.append(arr)
	return res

class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		if n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		else:
			ans = 0
			for col in range(n):
				ans += (-1) ** col * matrix[0][col] * self.determinantOfMatrix(getTruncatedMatrix(matrix, n, 0, col), n - 1)
			return ans


import numpy as np

class Solution:

	def cofactor(self, M, i, j):
		return [row[:j] + row[j + 1:] for row in M[:i] + M[i + 1:]]

	def determinantOfMatrix(self, M, n):
		if n == 1:
			return M[0][0]
		if n == 2:
			return M[0][0] * M[1][1] - M[0][1] * M[1][0]
		det = 0
		for i in range(n):
			sign = (-1) ** i
			subdet = self.determinantOfMatrix(self.cofactor(M, 0, i), n - 1)
			det += sign * M[0][i] * subdet
		return det


import numpy as np

class Solution:

	def determinantOfMatrix(self, M, n):
		det = np.linalg.det(M)
		return int(round(det))


import numpy as np

class Solution:

	def cofactor(self, arr, i, j):
		return [row[:j] + row[j + 1:] for row in arr[:i] + arr[i + 1:]]

	def determinantOfMatrix(self, arr, n):
		return int(round(np.linalg.det(arr)))


class Solution:

	def determinantOfMatrix(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		elif n == 2:
			a = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
			return a
		s = 0
		li = []
		for i in range(n):
			if matrix[0][i] == 0:
				continue
			for k in range(1, n):
				li1 = list(matrix[k])
				li1.pop(i)
				li.append(li1)
			if i % 2 == 0:
				s += matrix[0][i] * self.determinantOfMatrix(li, n - 1)
				li = []
			else:
				s -= matrix[0][i] * self.determinantOfMatrix(li, n - 1)
				li = []
		return s


class Solution:

	def determinantOfMatrix(self, matrix, n):
		return self.solve(matrix, n)

	def solve(self, matrix, n):
		if n == 1:
			return matrix[0][0]
		if n == 2:
			return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]
		matrix2 = [[0 for j in range(n - 1)] for i in range(n - 1)]
		total = 0
		for k in range(n):
			a = b = 0
			for i in range(1, n):
				b = 0
				for j in range(n):
					if j != k:
						matrix2[a][b] = matrix[i][j]
						b += 1
				a += 1
			t = self.determinantOfMatrix(matrix2, n - 1)
			total += (-1) ** k * matrix[0][k] * t
		return total


class Solution:

	def determinantOfMatrix(self, M, n):
		import numpy
		D = int(round(numpy.linalg.det(M)))
		return D


class Solution:

	def cofactor(self, m, i, j):
		return [row[:j] + row[j + 1:] for row in m[:i] + m[i + 1:]]

	def determinantOfMatrix(self, mat, n=float('inf')):
		if len(mat) == 1:
			return mat[0][0]
		if len(mat) == 2:
			return mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]
		res = 0
		for col in range(len(mat)):
			sign = (-1) ** col
			det = self.determinantOfMatrix(self.cofactor(mat, 0, col))
			res += sign * mat[0][col] * det
		return res


def determinant_recursive(A, total=0):
	indices = list(range(len(A)))
	if len(A) == 2 and len(A[0]) == 2:
		val = A[0][0] * A[1][1] - A[1][0] * A[0][1]
		return val
	for fc in indices:
		As = A
		As = As[1:]
		height = len(As)
		for i in range(height):
			As[i] = As[i][0:fc] + As[i][fc + 1:]
		sign = (-1) ** (fc % 2)
		sub_det = determinant_recursive(As)
		total += sign * A[0][fc] * sub_det
	return total

class Solution:

	def determinantOfMatrix(self, a, n):
		if n == 1:
			return a[0][0]
		return determinant_recursive(a)


class Solution:

	def cofactor_matrix(self, matrix, temp, p, q, n):
		(i, j) = (0, 0)
		for row in range(n):
			for column in range(n):
				if row != p and column != q:
					temp[i][j] = matrix[row][column]
					j += 1
					if j == n - 1:
						j = 0
						i += 1

	def determinantOfMatrix(self, matrix, n):
		answer = 0
		if n == 1:
			return matrix[0][0]
		temp = [[0 for i in range(n)] for j in range(n)]
		sign = 1
		for i in range(n):
			self.cofactor_matrix(matrix, temp, 0, i, n)
			answer += sign * matrix[0][i] * self.determinantOfMatrix(temp, n - 1)
			sign = -sign
		return answer


class Solution:

	def determinantOfMatrix(self, arr, n):
		if n == 1:
			return arr[0][0]
		else:
			b = [[0] * n for i in range(n)]
			s = 1
			det = 0
			for c in range(n):
				m = 0
				z = 0
				for i in range(n):
					for j in range(n):
						if i != 0 and j != c:
							b[m][z] = arr[i][j]
							if z < n - 2:
								z += 1
							else:
								z = 0
								m += 1
				det = det + arr[0][c] * s * self.determinantOfMatrix(b, n - 1)
				s = s * -1
			return det


def getcofactor(m, i, j):
	return [row[:j] + row[j + 1:] for row in m[:i] + m[i + 1:]]

class Solution:

	def determinantOfMatrix(self, mat, n=0):
		if len(mat) == 1:
			return mat[0][0]
		if len(mat) == 2:
			value = mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]
			return value
		Sum = 0
		for current_column in range(len(mat)):
			sign = (-1) ** current_column
			sub_det = self.determinantOfMatrix(getcofactor(mat, 0, current_column))
			Sum += sign * mat[0][current_column] * sub_det
		return Sum


import numpy as np

class Solution:

	def determinantOfMatrix(self, Matrix, n):
		D = np.linalg.det(Matrix)
		return int(round(D))


class Solution:

	def getfactor(self, matrix, n, row, col, temp):
		x = 0
		y = 0
		for i in range(n):
			for j in range(n):
				if i != row and j != col:
					temp[x][y] = matrix[i][j]
					y += 1
					if y == n - 1:
						y = 0
						x += 1

	def determinantOfMatrix(self, matrix, n):
		d = 0
		if n == 1:
			return matrix[0][0]
		temp = [[0 for _ in range(n)] for _ in range(n)]
		sign = 1
		for j in range(n):
			self.getfactor(matrix, n, 0, j, temp)
			d += sign * matrix[0][j] * self.determinantOfMatrix(temp, n - 1)
			sign *= -1
		return d