Given an integer N and a matrix A of dimensions NxN.Swap the values of the triangle above the primary diagonal with the values of the triangle below the primary diagonal.
Example 1:
Input:
N=3
A=[[1,2,3],[4,5,6],[7,8,9]]
Output:
1 4 7
2 5 8
3 6 9
Explanation:
Swapping the upper triangle with the
 lower triangle gives this result.
Example 2:
Input:
N=4
A=[[2,7,3,1],[10,1,5,1],[10,4,7,6],[6,9,1,8]]
Output:
2 10 10 6 
7 1 4 9 
3 5 7 1 
1 1 6 8
Explanation:
Swapping upper triangle with the
lower triangle leads to this result.
Your Task:
You don't need to read input or print anything. Your task is to complete the function swapTriangle() which takes the integer N and matrix A as input parameters and returns a matrix with the upper and lower triangles swapped.
Expected Time Complexity:O(N^{2})
Expected Auxillary Space:O(1)
 
Constraints:
1<=N,A[i][j]<=1000, for 0<=i

Difficulty: EASY
Tags: Matrices

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

Starter code:
#User function Template for python3

class Solution:
    def swapTriangle(self,N,A):
        #code here

Solutions:
class Solution:

	def swapTriangle(self, N, A):
		arr = []
		for i in range(N):
			row = [B[i] for B in A]
			arr.append(row)
		return arr


class Solution:

	def swapTriangle(self, N, A):
		for i in range(N):
			for j in range(i, N):
				(A[i][j], A[j][i]) = (A[j][i], A[i][j])
		return A


class Solution:

	def swapTriangle(self, N, A):
		m = []
		for i in range(N):
			for j in range(N):
				m.append(A[j][i])
		k = []
		for i in range(0, len(m), N):
			k.append(m[i:i + N])
		return k


class Solution:

	def swapTriangle(self, N, arr):
		isOk = []
		for i in range(N):
			for j in range(i, N):
				if i != j:
					(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
					isOk += sorted([i, j])
		return arr


class Solution:

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


import numpy as np

class Solution:

	def swapTriangle(self, N, A):
		m = []
		for i in range(N):
			m1 = []
			for j in range(N):
				m1.append(A[j][i])
			m.append(m1)
		return m


class Solution:

	def swapTriangle(self, N, A):
		copy = []
		for p in range(N):
			line = []
			for q in range(N):
				line.append(0)
			copy.append(line)
		for i in range(N):
			for j in range(N):
				copy[i][j] = A[j][i]
		return copy


class Solution:

	def swapTriangle(self, N, A):
		return list(zip(*A))


class Solution:

	def swapTriangle(self, n, A):
		(K, L) = ([], [])
		for i in range(n):
			for j in range(n):
				K.append(A[j][i])
		k = 0
		for i in range(n):
			for j in range(n):
				A[i][j] = K[k]
				k += 1
		return A


class Solution:

	def swapTriangle(self, N, A):
		for i in range(0, N):
			for j in range(i + 1, N):
				temp = A[i][j]
				A[i][j] = A[j][i]
				A[j][i] = temp
		return A


class Solution:

	def swapTriangle(self, N, A):
		for i in range(N):
			for j in range(N):
				if i == j:
					pass
				elif i > j:
					(A[i][j], A[j][i]) = (A[j][i], A[i][j])
		return A


class Solution:

	def swapTriangle(self, N, A):
		e = []
		for i in range(len(A)):
			l = []
			for j in range(len(A[i])):
				l.append(A[j][i])
			e.append(l)
		return e


class Solution:

	def swapTriangle(self, N, A):
		n = len(A)
		m = len(A[0])
		for i in range(m):
			for j in range(i, n):
				(A[i][j], A[j][i]) = (A[j][i], A[i][j])
		return A


class Solution:

	def swapTriangle(self, N, A):
		res = []
		for x in range(N):
			r = []
			for y in range(N):
				r.append(A[y][x])
			res.append(r)
		return res


class Solution:

	def swapTriangle(self, N, A):
		m = A[:]
		for i in range(N):
			for j in range(i + 1, N):
				x = A[i][j]
				A[i][j] = A[j][i]
				A[j][i] = x
		return A


class Solution:

	def swapTriangle(self, N, A):
		for i in range(N):
			for j in range(N):
				if i < j:
					(A[i][j], A[j][i]) = (A[j][i], A[i][j])
		return A
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [[0] * N] * N
		for i in range(N):
			A[i] = list(map(int, input().strip().split(' ')))
		ob = Solution()
		ans = ob.swapTriangle(N, A)
		for i in range(N):
			for j in range(N):
				print(ans[i][j], end=' ')
			print()


class Solution:

	def swapTriangle(self, N, A):
		a = []
		for i in range(0, N):
			for j in range(0, N):
				try:
					a[j].append(A[i][j])
				except:
					a.append([A[i][j]])
		return a


import numpy as np

class Solution:

	def swapTriangle(self, N, A):
		for i in range(N):
			for j in range(i, N):
				if i != j:
					(A[i][j], A[j][i]) = (A[j][i], A[i][j])
		return A


class Solution:

	def swapTriangle(self, N, A):
		B = []
		B = [[A[j][i] for j in range(N)] for i in range(len(A[0]))]
		return B


class Solution:

	def swapTriangle(self, N, arr):
		for i in range(0, N):
			for j in range(i, N):
				curr = arr[i][j]
				arr[i][j] = arr[j][i]
				arr[j][i] = curr
		return arr


class Solution:

	def swapTriangle(self, n, a):
		i = 0
		while i < n:
			j = i + 1
			while j < n:
				temp = a[i][j]
				a[i][j] = a[j][i]
				a[j][i] = temp
				j += 1
			i += 1
		return a


class Solution:

	def swapTriangle(self, N, A):
		for row in range(N):
			for col in range(row, N):
				(A[row][col], A[col][row]) = (A[col][row], A[row][col])
		return A


class Solution:

	def swapTriangle(self, N, A):
		my_list = list()
		for i in range(N):
			my_list.append([])
		for i in range(N):
			for j in range(N):
				my_list[i].append(A[j][i])
		return my_list


class Solution:

	def swapTriangle(self, N, A):
		z = []
		for x in range(N):
			l = []
			for y in range(N):
				l.append(A[y][x])
			z.append(l)
		return z


class Solution:

	def swapTriangle(self, N, A):
		ar = []
		for i in range(N):
			row = []
			for j in range(N):
				row.append(0)
			ar.append(row)
		for i in range(N):
			for j in range(N):
				ar[i][j] = A[j][i]
		return ar