Write a program to find the transpose of a square matrix of size N*N. Transpose of a matrix is obtained by changing rows to columns and columns to rows.
Example 1:
Input:
N = 4
mat[][] = {{1, 1, 1, 1},
           {2, 2, 2, 2}
           {3, 3, 3, 3}
           {4, 4, 4, 4}}
Output: 
{{1, 2, 3, 4},  
 {1, 2, 3, 4}  
 {1, 2, 3, 4}
 {1, 2, 3, 4}} 
Example 2:
Input:
N = 2
mat[][] = {{1, 2},
           {-9, -2}}
Output:
{{1, -9}, 
 {2, -2}}
Your Task:
You dont need to read input or print anything. Complete the function transpose() which takes matrix[][] and N as input parameter and finds the transpose of the input matrix. You need to do this in-place. That is you need to update the original matrix with the transpose. 
Expected Time Complexity: O(N * N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{3}
-10^{9} <= mat[i][j] <= 10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Matrices

Data structures

Starter code: #User function Template for python3

class Solution:
    def transpose(self, matrix, n):
        # Write Your code here

Solutions:
class Solution:

	def transpose(self, mat, n):
		for i in range(n):
			for j in range(i + 1, n):
				(mat[i][j], mat[j][i]) = (mat[j][i], mat[i][j])
		return mat


class Solution:

	def transpose(self, matrix, n):
		for i in range(n):
			for j in range(i, n):
				(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])


class Solution:

	def transpose(self, matrix, n):
		for i in range(n):
			for j in range(i + 1, n, 1):
				temp = matrix[i][j]
				matrix[i][j] = matrix[j][i]
				matrix[j][i] = temp
		return matrix


class Solution:

	def transpose(self, matrix, n):
		m = [[0 for x in range(n)] for y in range(n)]
		for i in range(n):
			for j in range(i + 1, n):
				(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])


class Solution:

	def transpose(self, matrix, n):
		for i in range(len(matrix)):
			for j in range(i, len(matrix[0])):
				(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])
		return matrix


class Solution:

	def transpose(self, matrix, n):
		lst = []
		for i in zip(*matrix):
			lst += [i]
		matrix[:] = lst[:]


class Solution:

	def transpose(self, matrix, n):
		res = [[column for column in range(n)] for row in range(n)]
		for i in range(n):
			for j in range(n):
				res[i][j] = matrix[j][i]
		for i in range(n):
			for j in range(n):
				matrix[i][j] = res[i][j]


class Solution:

	def transpose(self, matrix, n):
		new = []
		for i in range(n):
			u = []
			for j in range(n):
				u.append(matrix[j][i])
			new.append(u)
		for i in range(n):
			for j in range(n):
				matrix[i][j] = new[i][j]
		return matrix


class Solution:

	def transpose(self, matrix, N):
		for i in range(N):
			for j in range(i + 1, N):
				(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])
		return matrix


class Solution:

	def transpose(self, matrix, n):
		count = 0
		i = 0
		while i < n:
			j = count
			while j < n:
				temp = matrix[i][j]
				matrix[i][j] = matrix[j][i]
				matrix[j][i] = temp
				j += 1
			count += 1
			i += 1


class Solution:

	def transpose(self, a, n):
		for i in range(n):
			for j in range(i + 1, n):
				temp = a[i][j]
				a[i][j] = a[j][i]
				a[j][i] = temp


class Solution:

	def transpose(self, matrix, n):
		k = matrix.copy()
		for i in range(len(k)):
			l = []
			for j in range(len(k)):
				l.append(k[j][i])
			matrix[i] = l


class Solution:

	def transpose(self, matrix, n):
		mat2 = []
		for i in range(n):
			a = []
			for j in range(n):
				a.append(matrix[j][i])
			mat2.append(a)
		for i in range(n):
			for j in range(n):
				matrix[i][j] = mat2[i][j]


import numpy as np

class Solution:

	def transpose(self, matrix, n):
		for i in range(n):
			for j in range(i + 1, n):
				(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])
		return matrix


class Solution:

	def transpose(self, matrix, n):
		for r in range(len(matrix)):
			for c in range(r + 1, n):
				(matrix[r][c], matrix[c][r]) = (matrix[c][r], matrix[r][c])
		return matrix


class Solution:

	def transpose(self, matrix, n):
		for row in range(n):
			for col in range(row):
				(matrix[row][col], matrix[col][row]) = (matrix[col][row], matrix[row][col])
		return matrix


class Solution:

	def transpose(self, m, n):
		for i in range(n):
			for j in range(i, n):
				t = m[i][j]
				m[i][j] = m[j][i]
				m[j][i] = t
		return m


class Solution:

	def transpose(self, matrix, n):
		list1 = [[0 for i in range(1, n + 1)] for j in range(1, n + 1)]
		for i in range(n):
			for j in range(n):
				list1[i][j] = matrix[j][i]
		for i in range(len(list1)):
			matrix[i] = list1[i]


class Solution:

	def transpose(self, mat, n):
		mat2 = [[0 for i in range(n)] for i in range(n)]
		for i in range(n):
			for j in range(n):
				mat2[j][i] = mat[i][j]
		for i in range(n):
			for j in range(n):
				mat[i][j] = mat2[i][j]


class Solution:

	def transpose(self, arr, n):
		for i in range(n):
			for j in range(n):
				if i < j:
					(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])


class Solution:

	def transpose(self, matrix, n):
		for r in range(n):
			for c in range(r):
				(matrix[c][r], matrix[r][c]) = (matrix[r][c], matrix[c][r])


class Solution:

	def transpose(self, matrix, n):
		for row in range(len(matrix)):
			for column in range(row, len(matrix[row])):
				if row == column:
					continue
				else:
					(matrix[row][column], matrix[column][row]) = (matrix[column][row], matrix[row][column])
		return matrix


class Solution:

	def transpose(self, a, n):
		for i in range(len(a)):
			for j in range(i):
				(a[i][j], a[j][i]) = (a[j][i], a[i][j])
		return a