Given a N x N 2D matrix Arr representing an image. Rotate the image by 90 degrees (anti-clockwise). You need to do this in place. Note that if you end up using an additional array, you will only receive partial score.
Example 1:
Input:
N = 3
Arr[][] = {{1,  2,  3}
           {4,  5,  6}
           {7,  8,  9}}
Output:
 3  6  9 
 2  5  8 
 1  4  7 
Explanation: The given matrix is rotated
by 90 degree in anti-clockwise direction.
Example 2:
Input:
N = 4
Arr[][] = {{1,  2,  3,  4}
           {5,  6,  7,  8}
           {9, 10, 11, 12}
           {13, 14, 15, 16}}
Output:
 4  8 12 16 
 3  7 11 15 
 2  6 10 14 
 1  5  9 13
Explanation: The given matrix is rotated
by 90 degree in anti-clockwise direction.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function rotate() which takes the 2D array of integers arr and n as parameters and returns void. You need to change the array itself.
Expected Time Complexity: O(N*N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 1000
1 ≤ Arr[i][j] ≤ 1000

Difficulty: MEDIUM
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N*N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:

    

    def rotateMatrix(self,arr, n):

        # code here

Solutions:
class Solution:

	def rotateMatrix(self, arr, n):
		l = []
		for i in range(-1, -(len(arr) + 1), -1):
			k = []
			for j in range(len(arr)):
				k.append(arr[j][i])
			l.append(k)
		for i in range(len(arr)):
			arr[i] = l[i]


class Solution:

	def rotateMatrix(self, arr, n):
		lst = []
		for i in zip(*arr):
			lst.append(i)
		arr[:] = lst[::-1]


class Solution:

	def rotateMatrix(self, arr, n):
		n = len(arr)
		ans = [[0] * n for _ in range(n)]
		for i in range(n):
			for j in range(n):
				ans[i][j] = arr[j][i]
		ans = ans[::-1]
		for i in range(len(arr)):
			arr[i] = ans[i]


class Solution:

	def rotateMatrix(self, arr, n):

		def revc(arr):
			for i in range(n):
				j = 0
				k = n - 1
				while j < k:
					(arr[k][i], arr[j][i]) = (arr[j][i], arr[k][i])
					j += 1
					k -= 1

		def trn(arr):
			for i in range(n):
				for j in range(i, n):
					(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
		trn(arr)
		revc(arr)


class Solution:

	def rotateMatrix(self, arr, n):
		l = []
		for i in zip(*arr):
			l = [i] + l
		arr[:] = l[:]


class Solution:

	def rotateMatrix(self, arr, n):
		for x in range(len(arr)):
			for y in range(x, len(arr)):
				tmp = arr[x][y]
				arr[x][y] = arr[y][x]
				arr[y][x] = tmp
		for x in range(int(n / 2)):
			for y in range(n):
				tmp = arr[x][y]
				arr[x][y] = arr[n - 1 - x][y]
				arr[n - 1 - x][y] = tmp
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		for x in range(int(n / 2)):
			for y in range(n - 1 - x * 2):
				tmp1 = arr[x][y + x]
				tmp2 = arr[n - 1 - x - y][x]
				tmp3 = arr[n - 1 - x][n - 1 - x - y]
				tmp4 = arr[x + y][n - 1 - x]
				arr[x][y + x] = tmp4
				arr[n - 1 - x - y][x] = tmp1
				arr[n - 1 - x][n - 1 - x - y] = tmp2
				arr[x + y][n - 1 - x] = tmp3
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			arr[i].reverse()
		for i in range(n):
			for j in range(i, n):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			for j in range(i + 1, n):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
		for i in range(n):
			low = 0
			high = n - 1
			while low < high:
				(arr[low][i], arr[high][i]) = (arr[high][i], arr[low][i])
				low += 1
				high -= 1
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		s = 0
		e = n - 1
		while s <= e:
			for i in range(n):
				t = arr[i][s]
				arr[i][s] = arr[i][e]
				arr[i][e] = t
			s += 1
			e -= 1
		for i in range(n):
			for j in range(i + 1, n):
				t = arr[i][j]
				arr[i][j] = arr[j][i]
				arr[j][i] = t


class Solution:

	def rotateMatrix(self, arr, n):
		temp = [[0 for i in range(len(arr[0]))] for j in range(len(arr))]
		for i in range(len(arr)):
			for j in range(len(arr[0])):
				temp[j][i] = arr[i][len(arr) - 1 - j]
		for i in range(len(arr)):
			for j in range(len(arr[0])):
				arr[i][j] = temp[i][j]


class Solution:

	def rotateMatrix(self, arr, n):
		Output = arr[:]
		arr.clear()
		for i in range(1, n + 1):
			arr.append([])
			for j in range(n):
				arr[i - 1].append(Output[j][-i])


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n // 2):
			for j in range(i, n - 1 - i):
				temp = arr[i][j]
				arr[i][j] = arr[j][n - 1 - i]
				arr[j][n - 1 - i] = arr[n - 1 - i][n - 1 - j]
				arr[n - 1 - i][n - 1 - j] = arr[n - 1 - j][i]
				arr[n - 1 - j][i] = temp
		return arr


class Solution:

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


class Solution:

	def Reverse(self, arr):
		n = len(arr)
		for i in range(n // 2):
			(arr[i], arr[n - i - 1]) = (arr[n - i - 1], arr[i])
		return arr

	def rotateMatrix(self, arr, n):
		for i in range(n):
			arr[i] = self.Reverse(arr[i])
		for i in range(n):
			for j in range(i, n):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])


class Solution:

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

	def rotateMatrix(self, arr, n):
		for i in range(n):
			arr[i] = arr[i][::-1]
		self.transpose(arr)


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			arr[i] = arr[i][::-1]
		for i in range(0, n - 1):
			for j in range(i + 1, n):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
		return arr


class Solution:

	def transposeMatrix(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])
		return matrix

	def reverseMatrix(self, matrix):
		for row in matrix:
			row.reverse()
		return matrix

	def rotateMatrix(self, matrix, n):
		self.reverseMatrix(matrix)
		self.transposeMatrix(matrix, n)
		return matrix


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])
		return matrix

	def reverse1(self, matrix):
		for row in matrix:
			row.reverse()
		return matrix

	def rotateMatrix(self, matrix, n):
		self.reverse1(matrix)
		self.transpose(matrix, n)
		return matrix


class Solution:

	def rotateMatrix(self, a, n):
		i = 0
		while i < n // 2:
			for j in range(i, n - i - 1):
				x = j
				y = i
				temp1 = a[x][y]
				for k in range(4):
					temp2 = a[n - 1 - y][x]
					a[n - 1 - y][x] = temp1
					temp1 = temp2
					temp3 = x
					x = n - 1 - y
					y = temp3
			i += 1


class Solution:

	def rotateMatrix(self, matrix, n):
		for i in range(n):
			for j in range(i):
				(matrix[i][j], matrix[j][i]) = (matrix[j][i], matrix[i][j])
		for i in range(n // 2):
			(matrix[i], matrix[n - i - 1]) = (matrix[n - i - 1], matrix[i])


class Solution:

	def rotateMatrix(self, arr, n):
		for x in range(n // 2):
			for y in range(x, n - 1 - x):
				temp = arr[x][y]
				arr[x][y] = arr[y][n - 1 - x]
				arr[y][n - 1 - x] = arr[n - 1 - x][n - 1 - y]
				arr[n - 1 - x][n - 1 - y] = arr[n - 1 - y][x]
				arr[n - 1 - y][x] = temp


class Solution:

	def rotateMatrix(self, arr, n):
		l = []
		for i in range(n - 1, -1, -1):
			m = []
			for j in range(n):
				m.append(arr[j][i])
			l.append(m)
		for i in range(n):
			arr[i] = l[i]


class Solution:

	def rotateMatrix(self, arr, n):
		l = []
		for i in range(n - 1, -1, -1):
			for j in range(n):
				l.append(arr[j][i])
		a = 0
		for i in range(n):
			for j in range(n):
				arr[i][j] = l[a]
				a = a + 1


class Solution:

	def rotateMatrix(self, arr, n):
		l = 0
		r = n - 1
		t = 0
		b = n - 1
		while l < r:
			for i in range(r - l):
				temp1 = arr[t + i][l]
				temp2 = arr[t][r - i]
				temp3 = arr[b][l + i]
				temp4 = arr[b - i][r]
				arr[b][l + i] = temp1
				arr[b - i][r] = temp3
				arr[t][r - i] = temp4
				arr[t + i][l] = temp2
			l = l + 1
			r = r - 1
			t = l
			b = r
		return


class Solution:

	def rotateMatrix(self, a, n):
		for i in range(n):
			for j in range(i):
				(a[i][j], a[j][i]) = (a[j][i], a[i][j])
		i = 0
		k = n - 1
		for i in range(n):
			j = 0
			k = n - 1
			while j <= k:
				(a[j][i], a[k][i]) = (a[k][i], a[j][i])
				j += 1
				k -= 1
		return a


class Solution:

	def rotateMatrixRecurs(self, arr, n, depth):
		if depth >= n:
			return
		for i in range(0, n - depth - 1):
			(arr[depth][depth + i], arr[n - i - 1][depth], arr[n - 1][n - i - 1], arr[depth + i][n - 1]) = (arr[depth + i][n - 1], arr[depth][depth + i], arr[n - i - 1][depth], arr[n - 1][n - i - 1])
		self.rotateMatrixRecurs(arr, n - 1, depth + 1)

	def rotateMatrix(self, arr, n):
		self.rotateMatrixRecurs(arr, n, 0)


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			arr[i] = arr[i][::-1]
		row = 0
		while row < n:
			for cl in range(row, n):
				(arr[row][cl], arr[cl][row]) = (arr[cl][row], arr[row][cl])
			row += 1
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		for r in range(n - 1):
			for c in range(n - 1 - r):
				(arr[r][c], arr[n - 1 - c][n - 1 - r]) = (arr[n - 1 - c][n - 1 - r], arr[r][c])
		for row in arr:
			l = 0
			r = n - 1
			while l < r:
				(row[l], row[r]) = (row[r], row[l])
				l += 1
				r -= 1


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n - 1):
			for j in range(n - 1 - i):
				(arr[i][j], arr[n - 1 - j][n - 1 - i]) = (arr[n - 1 - j][n - 1 - i], arr[i][j])
		for row in arr:
			l = 0
			r = n - 1
			while l < r:
				(row[l], row[r]) = (row[r], row[l])
				l += 1
				r -= 1


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			for j in range(i + 1, n):
				temp = arr[i][j]
				arr[i][j] = arr[j][i]
				arr[j][i] = temp
		l = 0
		h = n - 1
		while l <= h:
			temp = arr[l]
			arr[l] = arr[h]
			arr[h] = temp
			l += 1
			h -= 1
		return


class Solution:

	def rotateMatrix(self, matrix, n):
		i1 = j1 = 0
		i2 = 0
		j2 = n - 1
		i3 = n - 1
		j3 = n - 1
		i4 = n - 1
		j4 = 0
		while j1 < j2:
			a = i1
			b = j1
			c = i2
			d = j2
			e = i3
			f = j3
			g = i4
			h = j4
			while j1 < j2:
				temp1 = matrix[i1][j1]
				temp2 = matrix[i4][j4]
				matrix[i4][j4] = temp1
				temp3 = matrix[i3][j3]
				matrix[i3][j3] = temp2
				temp4 = matrix[i2][j2]
				matrix[i2][j2] = temp3
				matrix[i1][j1] = temp4
				i1 += 1
				j2 -= 1
				i3 -= 1
				j4 += 1
			i1 = a + 1
			j1 = b + 1
			i2 = c + 1
			j2 = d - 1
			i3 = e - 1
			j3 = f - 1
			i4 = g - 1
			j4 = h + 1


class Solution:

	def rotateMatrix(self, arr, n):

		def swap(a, b, c, d):
			(arr[a][b], arr[c][d]) = (arr[c][d], arr[a][b])
		for l in range(n // 2):
			r = n - 1 - l
			for x in range(l + 1, n - l):
				swap(x, r, l, x)
				swap(r, n - 1 - x, x, r)
				swap(n - 1 - x, l, r, n - 1 - x)


import numpy as np

class Solution:

	def rotateMatrix(self, matrix, n):
		ls = np.ravel(matrix)
		d = len(matrix) - 1
		x = 0
		arr = []
		for i in range(0, len(matrix)):
			x = d
			temp = []
			for j in range(0, len(matrix)):
				temp.append(ls[x])
				x = x + n
			d -= 1
			arr.append(temp)
		for i in range(0, len(matrix)):
			matrix[i][:] = arr[i][:]
		return matrix


class Solution:

	def rotateMatrix(self, arr, n):
		a = []
		i = n - 1
		while i >= 0:
			for j in range(n):
				a.append(arr[j][i])
			i -= 1
		x = 0
		for i in range(n):
			for j in range(n):
				arr[i][j] = a[x]
				x += 1


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			for j in range(i):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
		mid = n // 2
		if n & 1:
			mid += 1
		for i in range(mid):
			(arr[i], arr[n - i - 1]) = (arr[n - i - 1], arr[i])
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		for i in zip(*arr):
			arr.insert(n, i)
		for i in range(n):
			arr.pop(0)
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			for j in range(1 + i, n):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
		for k in range(n // 2):
			for l in range(n):
				(arr[k][l], arr[n - 1 - k][l]) = (arr[n - 1 - k][l], arr[k][l])
		return arr


class Solution:

	def rotateMatrix(self, a, n):
		temp = []
		for i in range(len(a)):
			for j in range(i, len(a[0])):
				t = a[i][j]
				a[i][j] = a[j][i]
				a[j][i] = t
		for i in range(len(a) // 2):
			t = a[i]
			a[i] = a[len(a) - 1 - i]
			a[len(a) - 1 - i] = t
		return a


class Solution:

	def rotateMatrix(self, arr, n):
		for i in arr:
			i.reverse()
		for row in range(n):
			for col in range(row, n):
				(arr[col][row], arr[row][col]) = (arr[row][col], arr[col][row])


class Solution:

	def rotateMatrix(self, arr, n):
		for i in arr:
			i.reverse()
		m = len(arr[0])
		for row in range(n):
			for col in range(row, m):
				(arr[row][col], arr[col][row]) = (arr[col][row], arr[row][col])


class Solution:

	def rotateMatrix(self, arr, n):
		for row in range(n):
			for col in range(row):
				(arr[row][col], arr[col][row]) = (arr[col][row], arr[row][col])
		(start, end) = (0, n - 1)
		while start < end:
			(arr[start], arr[end]) = (arr[end], arr[start])
			start += 1
			end -= 1


class Solution:

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

	def reverse(self, arr, n):
		for i in range(n):
			j = 0
			k = n - 1
			while j < k:
				temp = arr[j][i]
				arr[j][i] = arr[k][i]
				arr[k][i] = temp
				j += 1
				k -= 1

	def rotateMatrix(self, arr, n):
		self.transpose(arr, n)
		self.reverse(arr, n)


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n - 1):
			for j in range(i + 1, n):
				temp = arr[i][j]
				arr[i][j] = arr[j][i]
				arr[j][i] = temp
		for i in range(n):
			j = 0
			while j < n // 2:
				temp = arr[j][i]
				arr[j][i] = arr[n - j - 1][i]
				arr[n - j - 1][i] = temp
				j += 1


class Solution:

	def rotateMatrix(self, arr, n):
		row_length = len(arr)
		column_length = len(arr[0])
		for i in range(row_length):
			for j in range(column_length // 2):
				(arr[i][j], arr[i][column_length - j - 1]) = (arr[i][column_length - j - 1], arr[i][j])
		for i in range(row_length):
			for j in range(i + 1, column_length):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])


class Solution:

	def rotateMatrix(self, mat, n):
		row = n
		col = n
		for i in range(row):
			for j in range(i + 1, col):
				(mat[i][j], mat[j][i]) = (mat[j][i], mat[i][j])
		for i in range(col):
			for j in range(row // 2):
				(mat[j][i], mat[row - j - 1][i]) = (mat[row - j - 1][i], mat[j][i])


class Solution:

	def rotateMatrix(self, arr, n):
		left = 0
		right = n - 1
		while left < right:
			for i in range(right - left):
				(top, bottom) = (left, right)
				temp = arr[top][left + i]
				arr[top][left + i] = arr[top + i][right]
				arr[top + i][right] = arr[bottom][right - i]
				arr[bottom][right - i] = arr[bottom - i][left]
				arr[bottom - i][left] = temp
			left += 1
			right -= 1
		return arr


class Solution:

	def rotateMatrix(self, arr, n):
		r = len(arr)
		c = len(arr[0])
		m = [[arr[i][j] for i in range(r)] for j in range(c - 1, -1, -1)]
		arr[:] = m


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n):
			for j in range(i + 1, n):
				(arr[i][j], arr[j][i]) = (arr[j][i], arr[i][j])
		left = 0
		right = n - 1
		while left < right:
			for i in range(0, n):
				(arr[left][i], arr[right][i]) = (arr[right][i], arr[left][i])
			left += 1
			right -= 1


class Solution:

	def rotateMatrix(self, mat, n):
		t = 0
		l = 0
		b = n - 1
		r = n - 1
		n = 0
		while t < b:
			for i in range(b - t):
				temp = mat[t][l + i]
				temp2 = mat[b - i][l]
				mat[b - i][l] = temp
				temp = temp2
				temp2 = mat[b][r - i]
				mat[b][r - i] = temp
				temp = temp2
				temp2 = mat[t + i][r]
				mat[t + i][r] = temp
				temp = temp2
				mat[t][l + i] = temp
			t += 1
			b -= 1
			r -= 1
			l += 1
			n += 1
		return mat


class Solution:

	def rotateMatrix(self, arr, n):
		for i in range(n - 1, -1, -1):
			temp = []
			for j in range(0, n):
				temp.append(arr[j][i])
			arr.append(temp)
		for i in range(n):
			arr.pop(0)