Banana-Leopard/TASTY huggingface dataset:
# Python3 implementation of smallest
# difference triplet
 
# Function to find maximum number
def maximum(a, b, c):
    return max(max(a, b), c)
 
# Function to find minimum number
def minimum(a, b, c):
    return min(min(a, b), c)
 
# Finds and prints the smallest
# Difference Triplet
def smallestDifferenceTriplet(arr1, arr2, arr3, n):
 
    # sorting all the three arrays
    arr1.sort()
    arr2.sort()
    arr3.sort()
 
    # To store resultant three numbers
    res_min = 0; res_max = 0; res_mid = 0
 
    # pointers to arr1, arr2,
    # arr3 respectively
    i = 0; j = 0; k = 0
 
    # Loop until one array reaches to its end
    # Find the smallest difference.
    diff = 2147483647
    while (i < n and j < n and k < n):
     
        sum = arr1[i] + arr2[j] + arr3[k]
 
        # maximum number
        max = maximum(arr1[i], arr2[j], arr3[k])
 
        # Find minimum and increment its index.
        min = minimum(arr1[i], arr2[j], arr3[k])
        if (min == arr1[i]):
            i += 1
        else if (min == arr2[j]):
            j += 1
        else:
            k += 1
 
        # Comparing new difference with the
        # previous one and updating accordingly
        if (diff > (max - min)):
         
            diff = max - min
            res_max = max
            res_mid = sum - (max + min)
            res_min = min
         
    # Print result
    print(res_max, ",", res_mid, ",", res_min)
 
# Driver code
arr1 = [5, 2, 8]
arr2 = [10, 7, 12]
arr3 = [9, 14, 6]
n = len(arr1)
smallestDifferenceTriplet(arr1, arr2, arr3, n)
 
# This code is contributed by Anant Agarwal.

Time complexity: nlogn
Space complexity: constant
# A simple Python 3 program
# to find three elements whose
# sum is equal to zero
 
# Prints all triplets in
# arr[] with 0 sum
 
 
def findTriplets(arr, n):
 
    found = False
    for i in range(0, n-2):
 
        for j in range(i+1, n-1):
 
            for k in range(j+1, n):
 
                if (arr[i] + arr[j] + arr[k] == 0):
                    print(arr[i], arr[j], arr[k])
                    found = True
 
    # If no triplet with 0 sum
    # found in array
    if (found == False):
        print(" not exist ")
 
 
# Driver code
arr = [0, -1, 2, -3, 1]
n = len(arr)
findTriplets(arr, n)
 
# This code is contributed by Smitha Dinesh Semwal

Time complexity: cubic
Space complexity: constant
# Python3 program to find triplets
# in a given array whose sum is zero
 
# function to print triplets with 0 sum
 
 
def findTriplets(arr, n):
    found = False
    for i in range(n - 1):
 
        # Find all pairs with sum
        # equals to "-arr[i]"
        s = set()
        for j in range(i + 1, n):
            x = -(arr[i] + arr[j])
            if x in s:
                print(x, arr[i], arr[j])
                found = True
            else:
                s.add(arr[j])
    if found == False:
        print("No Triplet Found")
 
 
# Driver Code
arr = [0, -1, 2, -3, 1]
n = len(arr)
findTriplets(arr, n)
 
# This code is contributed by Shrikant13

Time complexity: quadratic
Space complexity: linear
# python program to find triplets in a given
# array whose sum is zero
 
# function to print triplets with 0 sum
 
 
def findTriplets(arr, n):
 
    found = False
 
    # sort array elements
    arr.sort()
 
    for i in range(0, n-1):
 
        # initialize left and right
        l = i + 1
        r = n - 1
        x = arr[i]
        while (l < r):
 
            if (x + arr[l] + arr[r] == 0):
                # print elements if it's sum is zero
                print(x, arr[l], arr[r])
                l += 1
                r -= 1
                found = True
 
            # If sum of three elements is less
            # than zero then increment in left
            elif (x + arr[l] + arr[r] < 0):
                l += 1
 
            # if sum is greater than zero then
            # decrement in right side
            else:
                r -= 1
 
    if (found == False):
        print(" No Triplet Found")
 
 
# Driven source
arr = [0, -1, 2, -3, 1]
n = len(arr)
findTriplets(arr, n)
 
# This code is contributed by Smitha Dinesh Semwal

Time complexity: quadratic
Space complexity: constant
# Python program to rotate a matrix
 
# Function to rotate a matrix
def rotateMatrix(mat):
 
    if not len(mat):
        return
     
    """
        top : starting row index
        bottom : ending row index
        left : starting column index
        right : ending column index
    """
 
    top = 0
    bottom = len(mat)-1
 
    left = 0
    right = len(mat[0])-1
 
    while left < right and top < bottom:
 
        # Store the first element of next row,
        # this element will replace first element of
        # current row
        prev = mat[top+1][left]
 
        # Move elements of top row one step right
        for i in range(left, right+1):
            curr = mat[top][i]
            mat[top][i] = prev
            prev = curr
 
        top += 1
 
        # Move elements of rightmost column one step downwards
        for i in range(top, bottom+1):
            curr = mat[i][right]
            mat[i][right] = prev
            prev = curr
 
        right -= 1
 
        # Move elements of bottom row one step left
        for i in range(right, left-1, -1):
            curr = mat[bottom][i]
            mat[bottom][i] = prev
            prev = curr
 
        bottom -= 1
 
        # Move elements of leftmost column one step upwards
        for i in range(bottom, top-1, -1):
            curr = mat[i][left]
            mat[i][left] = prev
            prev = curr
 
        left += 1
 
    return mat
 
# Utility Function
def printMatrix(mat):
    for row in mat:
        print row
 
 
# Test case 1
matrix =[
            [1,  2,  3,  4 ],
            [5,  6,  7,  8 ],
            [9,  10, 11, 12 ],
            [13, 14, 15, 16 ] 
        ]
# Test case 2
"""
matrix =[
            [1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]
        ]
"""
 
matrix = rotateMatrix(matrix)
# Print modified matrix
printMatrix(matrix)

Time complexity: quadratic
Space complexity: constant
# Python3 program to rotate a matrix by 90 degrees
N = 4
 
# An Inplace function to rotate
# N x N matrix by 90 degrees in
# anti-clockwise direction
 
 
def rotateMatrix(mat):
 
    # Consider all squares one by one
    for x in range(0, int(N / 2)):
 
        # Consider elements in group
        # of 4 in current square
        for y in range(x, N-x-1):
 
            # store current cell in temp variable
            temp = mat[x][y]
 
            # move values from right to top
            mat[x][y] = mat[y][N-1-x]
 
            # move values from bottom to right
            mat[y][N-1-x] = mat[N-1-x][N-1-y]
 
            # move values from left to bottom
            mat[N-1-x][N-1-y] = mat[N-1-y][x]
 
            # assign temp to left
            mat[N-1-y][x] = temp
 
 
# Function to print the matrix
def displayMatrix(mat):
 
    for i in range(0, N):
 
        for j in range(0, N):
 
            print(mat[i][j], end=' ')
        print("")
 
 
# Driver Code
if __name__ == "__main__":
    mat = [[0 for x in range(N)] for y in range(N)]
 
    mat = [[1, 2, 3, 4],
           [5, 6, 7, 8],
           [9, 10, 11, 12],
           [13, 14, 15, 16]]
 
    # Function call
    rotateMatrix(mat)
 
    # Print rotated matrix
    displayMatrix(mat)
 
 
# This code is contributed by saloni1297

Time complexity: quadratic
Space complexity: constant
# Python program to rotate
# a matrix by 90 degrees
 
 
def rotateMatrix(mat):
 
    # reversing the matrix
    for i in range(len(mat)):
        mat[i].reverse()
 
    # make transpose of the matrix
    for i in range(len(mat)):
        for j in range(i, len(mat)):
 
            # swapping mat[i][j] and mat[j][i]
            mat[i][j], mat[j][i] = mat[j][i], mat[i][j]
 
 
# Function to print the matrix
def displayMatrix(mat):
 
    for i in range(0, len(mat)):
        for j in range(0, len(mat)):
            print(mat[i][j], end=' ')
        print()
 
 
# Driver code
if __name__ == "__main__":
    mat = [[1, 2, 3, 4],
           [5, 6, 7, 8],
           [9, 10, 11, 12],
           [13, 14, 15, 16]]
 
    # Function call
    rotateMatrix(mat)
 
    # Print rotated matrix
    displayMatrix(mat)
 
# This code is contributed by shivambhagat02(CC).

Time complexity: quadratic
Space complexity: constant
# Python3 program to
# rotate a matrix by
# 180 degrees
N = 3;
 
# Function to Rotate
# the matrix by 180 degree
def rotateMatrix(mat):
     
    # Simply print from
    # last cell to first cell.
    i = N - 1;
    while(i >= 0):
        j = N - 1;
        while(j >= 0):
            print(mat[i][j], end = " ");
            j = j - 1;
        print();
        i = i - 1;
 
# Driven code
mat = [[1, 2, 3],
       [ 4, 5, 6 ],
       [ 7, 8, 9 ]];
rotateMatrix(mat);
 
# This code is contributed
# by mits

Time complexity: quadratic
Space complexity: constant
# Python3 program for left rotation of matrix by 180
  
R = 4
C = 4
  
# Function to rotate the matrix by 180 degree
def reverseColumns(arr):
    for i in range(C):
        j = 0
        k = C-1
        while j < k:
            t = arr[j][i]
            arr[j][i] = arr[k][i]
            arr[k][i] = t
            j += 1
            k -= 1
             
# Function for transpose of matrix
def transpose(arr):
    for i in range(R):
        for j in range(i, C):
            t = arr[i][j]
            arr[i][j] = arr[j][i]
            arr[j][i] = t
  
# Function for display the matrix
def printMatrix(arr):
    for i in range(R):
        for j in range(C):
            print(arr[i][j], end = " ");
        print();
  
# Function to anticlockwise rotate matrix
# by 180 degree
def rotate180(arr):
    transpose(arr);
    reverseColumns(arr);
    transpose(arr);
    reverseColumns(arr);
  
# Driven code
arr = [ [ 1, 2, 3, 4 ],
        [ 5, 6, 7, 8 ],
        [9, 10, 11, 12 ],
        [13, 14, 15, 16 ] ];
rotate180(arr);
printMatrix(arr);

Time complexity: quadratic
Space complexity: constant
# Reverse Row at specified index in the matrix
def reverseRow(data, index):
     
    cols = len(data[index])
    for i in range(cols // 2):
        temp = data[index][i]
        data[index][i] = data[index][cols - i - 1]
        data[index][cols - i - 1] = temp
     
    return data
 
# Print Matrix data
def printMatrix(data):
     
    for i in range(len(data)):
        for j in range(len(data[0])):
            print(data[i][j], end = ' ')
         
        print()
 
# Rotate Matrix by 180 degrees
def rotateMatrix(data):
     
    rows = len(data)
    cols = len(data[0])
     
    if (rows % 2):
         
        # If N is odd reverse the middle
        # row in the matrix
        data = reverseRow(data, len(data) // 2)
         
        # Swap the value of matrix [i][j] with
        # [rows - i - 1][cols - j - 1] for half
        # the rows size.
        for i in range(rows // 2):
            for j in range(cols):
                temp = data[i][j]
                data[i][j] = data[rows - i - 1][cols - j - 1]
                data[rows - i - 1][cols - j - 1] = temp
         
        return data
         
# Driver Code
data = [ [ 1, 2, 3, 4, 5 ],
         [ 6, 7, 8, 9, 10 ],
         [ 11, 12, 13, 14, 15 ],
         [ 16, 17, 18, 19, 20 ],
         [ 21, 22, 23, 24, 25 ] ]
          
# Rotate Matrix
data = rotateMatrix(data)
 
# Print Matrix
printMatrix(data)
 
# This code is contributed by rohitsingh07052

Time complexity: quadratic
Space complexity: constant
# Python3 program to check if all rows
# of a matrix are rotations of each other
 
MAX = 1000
 
# Returns true if all rows of mat[0..n-1][0..n-1]
# are rotations of each other.
def isPermutedMatrix(mat, n) :
     
    # Creating a string that contains
    # elements of first row.
    str_cat = ""
    for i in range(n) :
        str_cat = str_cat + "-" + str(mat[0][i])
 
    # Concatenating the string with itself
    # so that substring search operations
    # can be performed on this
    str_cat = str_cat + str_cat
 
    # Start traversing remaining rows
    for i in range(1, n) :
         
        # Store the matrix into vector
        # in the form of strings
        curr_str = ""
         
        for j in range(n) :
            curr_str = curr_str + "-" + str(mat[i][j])
 
        # Check if the current string is present
        # in the concatenated string or not
        if (str_cat.find(curr_str)) :
            return True
             
    return False
 
# Driver code
if __name__ == "__main__" :
    n = 4
    mat = [[1, 2, 3, 4],
           [4, 1, 2, 3],
           [3, 4, 1, 2],
           [2, 3, 4, 1]]
     
    if (isPermutedMatrix(mat, n)):
        print("Yes")
    else :
        print("No")
         
# This code is contributed by Ryuga

Time complexity: cubic
Space complexity: linear
# Python3 implementation to sort
# the given matrix
 
SIZE = 10
 
# Function to sort the given matrix
def sortMat(mat, n) :
     
    # Temporary matrix of size n^2
    temp = [0] * (n * n)
    k = 0
 
    # Copy the elements of matrix 
    # one by one into temp[]
    for i in range(0, n) :
         
        for j in range(0, n) :
             
            temp[k] = mat[i][j]
            k += 1
 
    # sort temp[]
    temp.sort()
     
    # copy the elements of temp[]
    # one by one in mat[][]
    k = 0
     
    for i in range(0, n) :
         
        for j in range(0, n) :
            mat[i][j] = temp[k]
            k += 1
 
 
# Function to print the given matrix
def printMat(mat, n) :
     
    for i in range(0, n) :
         
        for j in range( 0, n ) :
             
            print(mat[i][j] , end = " ")
             
        print()
     
     
# Driver program to test above
mat = [ [ 5, 4, 7 ],
        [ 1, 3, 8 ],
        [ 2, 9, 6 ] ]
n = 3
 
print( "Original Matrix:")
printMat(mat, n)
 
sortMat(mat, n)
 
print("\nMatrix After Sorting:")
printMat(mat, n)
 
 
# This code is contributed by Nikita Tiwari.

Time complexity: quadratic
Space complexity: quadratic
# Python program to find median of matrix
# sorted row wise
 
from bisect import bisect_right as upper_bound
 
MAX = 100;
 
# Function to find median in the matrix
def binaryMedian(m, r, d):
    mi = m[0][0]
    mx = 0
    for i in range(r):
        if m[i][0] < mi:
            mi = m[i][0]
        if m[i][d-1] > mx :
            mx =  m[i][d-1]
     
    desired = (r * d + 1) // 2
     
    while (mi < mx):
        mid = mi + (mx - mi) // 2
        place = [0];
         
        # Find count of elements smaller than or equal to mid
        for i in range(r):
             j = upper_bound(m[i], mid)
             place[0] = place[0] + j
        if place[0] < desired:
            mi = mid + 1
        else:
            mx = mid
    print ("Median is", mi)
    return   
     
# Driver code
r, d = 3, 3
 
m = [ [1, 3, 5], [2, 6, 9], [3, 6, 9]]
binaryMedian(m, r, d)
 
# This code is contributed by Sachin BIsht

Time complexity: nlogn
Space complexity: constant
# Recursive code for Matrix Multiplication
MAX = 100
i = 0
j = 0
k = 0
 
def multiplyMatrixRec(row1, col1, A,
                      row2, col2, B, C):
                           
    # Note that below variables are static
    # i and j are used to know current cell of
    # result matrix C[][]. k is used to know
    # current column number of A[][] and row
    # number of B[][] to be multiplied
    global i
    global j
    global k
     
    # If all rows traversed.
    if (i >= row1):
        return
         
    # If i < row1
    if (j < col2):
        if (k < col1):
            C[i][j] += A[i][k] * B[k][j]
            k += 1
            multiplyMatrixRec(row1, col1, A,
                              row2, col2,B, C)
 
        k = 0
        j += 1
        multiplyMatrixRec(row1, col1, A,
                          row2, col2, B, C)
 
    j = 0
    i += 1
    multiplyMatrixRec(row1, col1, A,
                      row2, col2, B, C)
 
# Function to multiply two matrices
# A[][] and B[][]
def multiplyMatrix(row1, col1, A, row2, col2, B):
    if (row2 != col1):
        print("Not Possible")
        return
 
    C = [[0 for i in range(MAX)]
            for i in range(MAX)]
    multiplyMatrixRec(row1, col1, A,
                      row2, col2, B, C)
     
    # Print the result
    for i in range(row1):
        for j in range(col2):
            print( C[i][j], end = " ")
        print()
 
# Driver Code
A = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
B = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]
 
row1 = 3
col1 = 3
row2 = 3
col2 = 3
multiplyMatrix(row1, col1, A, row2, col2, B)
 
# This code is contributed by sahilshelangia

Time complexity: quadratic
Space complexity: logn
# Python3 program to print Lower
# triangular and Upper triangular
# matrix of an array
 
# Function to form lower triangular
# matrix
def lower(matrix, row, col):
 
     
    for i in range(0, row):
     
        for j in range(0, col):
         
            if (i < j):
             
                print("0", end = " ");
             
            else:
                print(matrix[i][j],
                       end = " " );
         
        print(" ");
     
# Function to form upper triangular matrix
def upper(matrix, row, col):
 
    for i in range(0, row):
     
        for j in range(0, col):
         
            if (i > j):
                print("0", end = " ");
             
            else:
                print(matrix[i][j],
                       end = " " );
         
        print(" ");
 
# Driver Code
matrix = [[1, 2, 3],
          [4, 5, 6],
          [7, 8, 9]];
row = 3;
col = 3;
     
print("Lower triangular matrix: ");
lower(matrix, row, col);
     
print("Upper triangular matrix: ");
upper(matrix, row, col);
         
# This code is contributed by
# Shivi_Aggarwal

Time complexity: quadratic
Space complexity: constant
# python3 program for the above approach
 
 
def spiralOrder(matrix):
    ans = []
 
    if (len(matrix) == 0):
        return ans
 
    m = len(matrix)
    n = len(matrix[0])
    seen = [[0 for i in range(n)] for j in range(m)]
    dr = [0, 1, 0, -1]
    dc = [1, 0, -1, 0]
    x = 0
    y = 0
    di = 0
 
    # Iterate from 0 to R * C - 1
    for i in range(m * n):
        ans.append(matrix[x][y])
        seen[x][y] = True
        cr = x + dr[di]
        cc = y + dc[di]
 
        if (0 <= cr and cr < m and 0 <= cc and cc < n and not(seen[cr][cc])):
            x = cr
            y = cc
        else:
            di = (di + 1) % 4
            x += dr[di]
            y += dc[di]
    return ans
 
 
# Driver code
if __name__ == "__main__":
    a = [[1, 2, 3, 4],
         [5, 6, 7, 8],
         [9, 10, 11, 12],
         [13, 14, 15, 16]]
 
    # Function call
    for x in spiralOrder(a):
        print(x, end=" ")
    print()

Time complexity: linear
Space complexity: linear
# Python3 program to print
# given matrix in spiral form
 
 
def spiralPrint(m, n, a):
    k = 0
    l = 0
 
    ''' k - starting row index
        m - ending row index
        l - starting column index
        n - ending column index
        i - iterator '''
 
    while (k < m and l < n):
 
        # Print the first row from
        # the remaining rows
        for i in range(l, n):
            print(a[k][i], end=" ")
 
        k += 1
 
        # Print the last column from
        # the remaining columns
        for i in range(k, m):
            print(a[i][n - 1], end=" ")
 
        n -= 1
 
        # Print the last row from
        # the remaining rows
        if (k < m):
 
            for i in range(n - 1, (l - 1), -1):
                print(a[m - 1][i], end=" ")
 
            m -= 1
 
        # Print the first column from
        # the remaining columns
        if (l < n):
            for i in range(m - 1, k - 1, -1):
                print(a[i][l], end=" ")
 
            l += 1
 
 
# Driver Code
a = [[1, 2, 3, 4],
     [5, 6, 7, 8],
     [9, 10, 11, 12],
     [13, 14, 15, 16]]
 
R = 4
C = 4
 
# Function Call
spiralPrint(R, C, a)
 
# This code is contributed by Nikita Tiwari.

Time complexity: quadratic
Space complexity: constant
# Python3 program for the above approach
 
# Function for printing matrix in spiral
# form i, j: Start index of matrix, row
# and column respectively m, n: End index
# of matrix row and column respectively
 
 
def printdata(arr, i, j, m, n):
 
    # If i or j lies outside the matrix
    if (i >= m or j >= n):
        return
 
    # Print First Row
    for p in range(i, n):
        print(arr[i][p], end=" ")
 
    # Print Last Column
    for p in range(i + 1, m):
        print(arr[p][n - 1], end=" ")
 
    # Print Last Row, if Last and
    # First Row are not same
    if ((m - 1) != i):
        for p in range(n - 2, j - 1, -1):
            print(arr[m - 1][p], end=" ")
 
    # Print First Column, if Last and
    # First Column are not same
    if ((n - 1) != j):
        for p in range(m - 2, i, -1):
            print(arr[p][j], end=" ")
 
    printdata(arr, i + 1, j + 1, m - 1, n - 1)
 
 
# Driver code
if __name__ == "__main__":
    R = 4
    C = 4
    arr = [[1, 2, 3, 4],
           [5, 6, 7, 8],
           [9, 10, 11, 12],
           [13, 14, 15, 16]]
 
    # Function Call
    printdata(arr, 0, 0, R, C)
 
# This code is contributed by avsadityavardhan

Time complexity: quadratic
Space complexity: constant
# Python3 program for the above approach
 
R = 4
C = 4
 
 
def isInBounds(i, j):
    global R
    global C
    if (i < 0 or i >= R or j < 0 or j >= C):
        return False
    return True
 
# Check if the position is blocked
 
 
def isBlocked(matrix, i, j):
    if (not isInBounds(i, j)):
        return True
    if (matrix[i][j] == -1):
        return True
 
    return False
 
# DFS code to traverse spirally
 
 
def spirallyDFSTravserse(matrix, i, j, Dir, res):
    if (isBlocked(matrix, i, j)):
        return
 
    allBlocked = True
    for k in range(-1, 2, 2):
        allBlocked = allBlocked and isBlocked(
            matrix, k + i, j) and isBlocked(matrix, i, j + k)
 
    res.append(matrix[i][j])
    matrix[i][j] = -1
    if (allBlocked):
        return
 
    # dir: 0 - right, 1 - down, 2 - left, 3 - up
    nxt_i = i
    nxt_j = j
    nxt_dir = Dir
    if (Dir == 0):
        if (not isBlocked(matrix, i, j + 1)):
            nxt_j += 1
        else:
            nxt_dir = 1
            nxt_i += 1
 
    elif(Dir == 1):
        if (not isBlocked(matrix, i + 1, j)):
            nxt_i += 1
        else:
            nxt_dir = 2
            nxt_j -= 1
 
    elif(Dir == 2):
        if (not isBlocked(matrix, i, j - 1)):
            nxt_j -= 1
        else:
            nxt_dir = 3
            nxt_i -= 1
 
    elif(Dir == 3):
        if (not isBlocked(matrix, i - 1, j)):
            nxt_i -= 1
        else:
            nxt_dir = 0
            nxt_j += 1
 
    spirallyDFSTravserse(matrix, nxt_i, nxt_j, nxt_dir, res)
 
# To traverse spirally
 
 
def spirallyTraverse(matrix):
    res = []
    spirallyDFSTravserse(matrix, 0, 0, 0, res)
    return res
 
 
# Driver code
if __name__ == "__main__":
    a = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
 
    # Function Call
    res = spirallyTraverse(a)
    print(*res)
 
# This code is contributed by rag2127

Time complexity: quadratic
Space complexity: constant
# Python program to find unique element in matrix
 
# function that calculate unique element
def unique(mat, r, c) -> int:
   
    # declare map for hashing
    mp = {}
    for i in range(r):
        for j in range(c):
           
            # increase freq of mat[i][j] in map
            if mat[i][j] not in mp:
                mp[mat[i][j]] = 1
            else:
                mp[mat[i][j]] += 1
    flag = False
     
    # print unique element
    for p in mp:
        if mp[p] == 1:
            print(p, end=" ")
            flag = True
    if flag == False:
        print("No unique element in the matrix")
 
 
# Driver program
if __name__ == "__main__":
    mat = [[1, 2, 3, 20], [5, 6, 20, 25], [1, 3, 5, 6], [6, 7, 8, 15]]
     
    # function that calculate unique element
    unique(mat, 4, 4)
 
    # This code is contributed by ajaymakvana

Time complexity: quadratic
Space complexity: quadratic