Geek is very fond of patterns. Once, his teacher gave him a square pattern to solve. He gave Geek an integer n and asked him to build a pattern.
Help Geek to build the pattern.
 
Example 1:
Input: 4
Output:
4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
Your Task:
You don't need to input anything. Complete the function printSquare() which takes  an integer n  as the input parameter and print the pattern.
Constraints:
	1<= N <= 20

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3



class Solution:

    def printTriangle(self, N):

        # Code here

Solutions:
class Solution:

	def printTriangle(self, n):
		for i in range(2 * n - 1):
			for j in range(2 * n - 1):
				print(n - min(i, j, 2 * n - 2 - j, 2 * n - 2 - i), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(0, 2 * N - 1):
			for j in range(0, 2 * N - 1):
				for x in range(N):
					if i in [x, 2 * N - (x + 2)] and j in range(x, 2 * N - (x + 1)) or (j in [x, 2 * N - (x + 2)] and i in range(x, 2 * N - (x + 1))):
						print(N - x, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(2 * N - 1):
			for j in range(2 * N - 1):
				top = i
				left = j
				bottom = 2 * N - 2 - i
				right = 2 * N - 2 - j
				print(N - min(min(top, bottom), min(left, right)), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(1, 2 * N, 1):
			if i > N:
				temp1 = 2 * N - i
			else:
				temp1 = i
			for j in range(1, 2 * N, 1):
				if j > N:
					temp2 = 2 * N - j
				else:
					temp2 = j
				mini = min(temp1, temp2)
				print(N - mini + 1, '', end='')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(0, 2 * N - 1, 1):
			for j in range(0, 2 * N - 1, 1):
				print(N - min(i, j, 2 * N - i - 2, 2 * N - 2 - j), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		i = 0
		while i < 2 * N - 1:
			j = 0
			while j < 2 * N - 1:
				top = i
				left = j
				bottom = 2 * (N - 1) - i
				right = 2 * (N - 1) - j
				print(N - min(top, left, bottom, right), end=' ')
				j += 1
			print()
			i += 1


class Solution:

	def printTriangle(self, N):
		m = 2 * N - 1
		for i in range(m):
			for j in range(m):
				top = i
				left = j
				right = abs(m - 1 - j)
				bottom = abs(m - 1 - i)
				curr_val = min(min(top, bottom), min(left, right))
				print(str(N - curr_val) + ' ', end='')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(1, N + 1):
			for j in range(i):
				print(N - j, end=' ')
			space = N * 2 - i * 2 - 1
			for j in range(space):
				print(N - i + 1, end=' ')
			for j in range(i, 0, -1):
				if N - j + 1 == 1:
					continue
				else:
					print(N - j + 1, end=' ')
			print()
		for i in range(N - 1, 0, -1):
			for j in range(i):
				print(N - j, end=' ')
			space = N * 2 - i * 2 - 1
			for j in range(space):
				print(N - i + 1, end=' ')
			for j in range(i, 0, -1):
				if N - j + 1 == 1:
					continue
				else:
					print(N - j + 1, end=' ')
			print()


class Solution:

	def printTriangle(self, n):
		for i in range(2 * n - 1):
			for j in range(2 * n - 1):
				top = i
				left = j
				right = 2 * n - 2 - j
				down = 2 * n - 2 - i
				value = n - min(top, down, left, right)
				print(value, end=' ')
			print()


class Solution:

	def printTriangle(self, n):
		for i in range(1, 2 * n):
			for j in range(1, 2 * n):
				x = abs(i - n) + 1
				y = abs(j - n) + 1
				print(max(x, y), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		if N <= 9:
			l = []
			for i in range(N, 0, -1):
				s = str(N) + ' '
				k = N
				for j in range(0, N - i):
					k = k - 1
					s = s + str(k) + ' '
				s = s + (i - 1) * (str(k) + ' ')
				r = s[::-1]
				s = s + r[3:]
				l.append(s)
			l = l + l[::-1][1:]
			for i in l:
				print(i)
		else:
			l = []
			for i in range(N, 0, -1):
				r = []
				r.append(N)
				k = N
				for j in range(0, N - i):
					k = k - 1
					r.append(k)
				for m in range(0, i - 1):
					r.append(k)
				u = r[::-1][1:]
				s = r + u
				l.append(s)
			l = l + l[::-1][1:]
			for i in l:
				print(' '.join(map(str, i)))


class Solution:

	def printTriangle(self, N):
		(l, r) = (0, 2 * N - 1)
		(t, b) = (0, 2 * N - 1)
		p = N
		m = []
		for i in range(2 * N - 1):
			q = []
			for j in range(2 * N - 1):
				q.append(0)
			m.append(q)
		while l <= r and t <= b:
			for i in range(l, r):
				m[t][i] = p
			t += 1
			for i in range(t, b):
				m[i][r - 1] = p
			r -= 1
			if t <= b:
				for i in range(r - 1, l - 1, -1):
					m[b - 1][i] = p
				b -= 1
			if l <= r:
				for i in range(b - 1, t - 1, -1):
					m[i][l] = p
				l += 1
			p -= 1
		for i in m:
			print(*i)


class Solution:

	def printTriangle(self, n):
		for i in range(1, 2 * n):
			for j in range(1, 2 * n):
				a = abs(i - n)
				b = abs(j - n)
				if a > b:
					m = a
				else:
					m = b
				print(m + 1, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(1, 2 * N):
			for j in range(1, 2 * N):
				min_dist = min(i - 1, j - 1, 2 * N - i - 1, 2 * N - j - 1)
				num = N - min_dist
				print(num, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(1, N + 1):
			for j in range(1, N + 1):
				if i < j:
					print(N + 1 - i, end=' ')
				else:
					print(N + 1 - j, end=' ')
			for j in reversed(range(1, N)):
				if i < j:
					print(N + 1 - i, end=' ')
				else:
					print(N + 1 - j, end=' ')
			print()
		for i in reversed(range(1, N)):
			for j in range(1, N + 1):
				if i < j:
					print(N + 1 - i, end=' ')
				else:
					print(N + 1 - j, end=' ')
			for j in reversed(range(1, N)):
				if i < j:
					print(N + 1 - i, end=' ')
				else:
					print(N + 1 - j, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(1, 2 * N):
			for j in range(1, 2 * N):
				(row, col) = (i, j)
				if row > N:
					row = 2 * N - row
				if col > N:
					col = 2 * N - col
				print(N - min(row, col) + 1, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for row in range(2 * N - 1):
			for col in range(2 * N - 1):
				print(N - min(row, col, 2 * N - 2 - row, 2 * N - 2 - col), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(0, 2 * N - 1):
			if i < N:
				row = i
			else:
				row = 2 * N - 2 - i
			value = N
			count = row
			for j in range(1, 2 * N):
				print(value, end=' ')
				if value > 0 and count > 0:
					value = value - 1
					count = count - 1
				elif j >= 2 * N - 1 - row and count == 0:
					value = value + 1
			print('\n', end='')


class Solution:

	def printTriangle(self, N):
		lis = [N + 1 for i in range(N)]
		result = []
		for i in range(N):
			for j in range(i, N):
				lis[j] -= 1
			lis1 = lis.copy()
			lis1.pop()
			lis2 = lis1[::-1]
			result.append(lis + lis2)
		for x in result:
			print(*x)
		result.pop()
		for y in result[::-1]:
			print(*y)


class Solution:

	def printTriangle(self, N):
		n = N
		for i in range(1, 2 * n - 1 + 1):
			distinct_number = i if i <= n else n * 2 - 1 - i + 1
			start = n
			to_fill_gap = n * 2 - 1 - (distinct_number - 1) * 2
			for x in range(1, distinct_number):
				print(start, end=' ')
				start -= 1
			for x in range(to_fill_gap):
				print(start, end=' ')
			for x in range(1, distinct_number):
				start += 1
				print(start, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		c = N
		s = ''
		k = ''
		l = []
		for j in range(N):
			h = s + (' ' + str(c)) * (2 * (N - j) - 1) + ' ' + k
			h = h.strip()
			print(h)
			l.append(h)
			s += ' ' + str(c)
			k = str(c) + ' ' + k
			c -= 1
		for j in range(N - 2, -1, -1):
			print(l[j])


class Solution(object):

	def printTriangle(self, N):
		for row in range(2 * N - 1):
			for col in range(2 * N - 1):
				left = col
				top = row
				right = 2 * N - 1 - col - 1
				bottom = 2 * N - 1 - row - 1
				val = N - min(min(left, right), min(top, bottom))
				print(val, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for row in range(1, N * 2):
			for col in range(1, N * 2):
				x = abs(N - row) + 1
				y = abs(N - col) + 1
				print(max(x, y), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(N):
			k = 0
			j = N
			while k < i:
				print(j, end=' ')
				k += 1
				j -= 1
			while k < 2 * N - i - 2:
				print(j, end=' ')
				k += 1
			while k < 2 * N - 1:
				print(j, end=' ')
				k += 1
				j += 1
			print()
		for i in range(N - 2, -1, -1):
			k = 0
			j = N
			while k < i:
				print(j, end=' ')
				k += 1
				j -= 1
			while k < 2 * N - i - 2:
				print(j, end=' ')
				k += 1
			while k < 2 * N - 1:
				print(j, end=' ')
				k += 1
				j += 1
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(2 * N - 1):
			for j in range(2 * N - 1):
				num = 0
				for k in range(N):
					if i == num or i == 2 * N - 2 - num or j == num or (j == 2 * N - 2 - num):
						break
					else:
						num += 1
				print(N - num, end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(2 * N - 1):
			distTop = i
			distBottom = 2 * N - 2 - i
			for j in range(2 * N - 1):
				distLeft = 2 * N - 2 - j
				distRight = j
				finalVal = N - min(min(distTop, distBottom), min(distLeft, distRight))
				print(str(finalVal) + ' ', end='')
			print()


class Solution:

	def printTriangle(self, n):
		spaces = 2 * n - 3
		for i in range(n - 1):
			for j in range(i + 1):
				print(n - j, end=' ')
			for j in range(spaces):
				print(n - i, end=' ')
			for j in range(i, -1, -1):
				print(n - j, end=' ')
			print()
			spaces -= 2
		num = n
		for i in range(2 * n - 1):
			print(num, end=' ')
			if i >= (2 * n - 1) // 2:
				num += 1
			else:
				num -= 1
			spaces -= 2
		print()
		spaces = 1
		for i in range(1, n):
			for j in range(n - i):
				print(n - j, end=' ')
			for j in range(spaces):
				print(i + 1, end=' ')
			for j in range(n - i - 1, -1, -1):
				print(n - j, end=' ')
			print()
			spaces += 2


class Solution:

	def printTriangle(self, a):
		for i in range(N):
			for j in range(N, N - i, -1):
				print(j, end=' ')
			for j in range(1, N - i):
				print(N - i, end=' ')
			for j in range(1, N - i):
				print(N - i, end=' ')
			for j in range(N - i, N + 1):
				print(j, end=' ')
			print()
		for i in range(1, N):
			for j in range(N, i, -1):
				print(j, end=' ')
			for j in range(i):
				print(i + 1, end=' ')
			for j in range(i):
				print(i + 1, end=' ')
			for j in range(i + 2, N + 1):
				print(j, end=' ')
			print()


class Solution:

	def pattern(self, i, N, res):
		(a, b) = (N - i, N - i)
		while b <= N + i - 2:
			res[a][b] = i
			b += 1
		(a, b) = (N - i, N + i - 2)
		while a <= N + i - 2:
			res[a][b] = i
			a += 1
		(a, b) = (N + i - 2, N + i - 2)
		while b >= N - i:
			res[a][b] = i
			b -= 1
		(a, b) = (N + i - 2, N - i)
		while a >= N - i:
			res[a][b] = i
			a -= 1

	def printTriangle(self, N):
		res = []
		for i in range(2 * N - 1):
			res.append([0] * (2 * N - 1))
		for i in range(N, 0, -1):
			self.pattern(i, N, res)
		for i in range(0, len(res)):
			for j in range(len(res[i])):
				print(res[i][j], end=' ')
			print(end='\n')


class Solution:

	def printTriangle(self, N):
		for i in range(N, 1, -1):
			for k in range(N - i):
				print(N - k, '', end='')
			for j in range(2 * i - 1):
				print(i, '', end='')
			for l in range(1, N - i + 1):
				print(i + l, '', end='')
			print()
		print(*[i for i in range(N, 1, -1)], *[i for i in range(1, N + 1)])
		for i in range(2, N + 1):
			for k in range(N - i):
				print(N - k, '', end='')
			for j in range(2 * i - 1):
				print(i, '', end='')
			for l in range(1, N - i + 1):
				print(i + l, '', end='')
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(N - 1):
			l = []
			for j in range(N):
				print(N - min(i, j), end=' ')
				l.append(N - min(i, j))
			l.pop()
			l.reverse()
			for k in range(len(l)):
				print(l[k], end=' ')
			print()
		for a in range(N, 0, -1):
			print(a, end=' ')
		for a in range(2, N + 1):
			print(a, end=' ')
		print()
		for i in range(N - 2, -1, -1):
			l = []
			for j in range(N):
				print(N - min(i, j), end=' ')
				l.append(N - min(i, j))
			l.pop()
			l.reverse()
			for k in range(len(l)):
				print(l[k], end=' ')
			print()


class Solution:

	def placeValues(self, l, i, n):
		(a, b) = (n - i, n - i)
		while b <= n + i - 2:
			l[a][b] = i
			b += 1
		(a, b) = (n - i, n + i - 2)
		while a <= n + i - 2:
			l[a][b] = i
			a += 1
		(a, b) = (n + i - 2, n + i - 2)
		while b >= n - i:
			l[a][b] = i
			b -= 1
		(a, b) = (n + i - 2, n - i)
		while a >= n - i:
			l[a][b] = i
			a -= 1

	def printTriangle(self, N):
		l = []
		for i in range(2 * N - 1):
			l.append([0] * (2 * N - 1))
		for i in range(N, 0, -1):
			self.placeValues(l, i, N)
		for i in l:
			print(*i)


class Solution:

	def printTriangle(self, N):
		k = 2 * N - 1
		num = N
		temp = N - 1
		numb = 1
		count = 0
		for i in range(N):
			num = N
			for j in range(count):
				print(num, end=' ')
				num -= 1
			for j in range(k):
				print(num, end=' ')
			k -= 2
			numb = N - i + 1
			for j in range(count):
				print(numb, end=' ')
				numb += 1
			count += 1
			print()
		count = 1
		for i in range(N - 1):
			num = N
			for j in range(temp):
				print(num, end=' ')
				num -= 1
			for j in range(count):
				print(num + 1, end=' ')
			count += 2
			numb = i + 2
			for j in range(temp):
				print(numb, end=' ')
				numb += 1
			temp -= 1
			print()


class Solution:

	def printTriangle(self, N):
		for i in range(1, 2 * N):
			for j in range(1, 2 * N):
				print(max(abs(N - i) + 1, abs(N - j) + 1), end=' ')
			print(' ')


class Solution:

	def printTriangle(self, N):
		for i in range(2 * N - 1):
			for j in range(2 * N - 1):
				t = i
				l = j
				r = 2 * N - 2 - j
				b = 2 * N - 2 - i
				print(N - min(min(t, b), min(l, r)), end=' ')
			print()


class Solution:

	def printTriangle(self, N):
		for row in range(2 * N - 1):
			for column in range(2 * N - 1):
				top = row
				left = column
				right = 2 * N - 2 - column
				bottom = 2 * N - 2 - row
				print(N - min(top, left, right, bottom), '', end='')
			print()


class Solution:

	def printTriangle(self, N):
		char = str(N) + ' '
		counter = N * 2 - 1
		for i in range(N, 0, -1):
			for j in range(N, i, -1):
				print(j, end=' ')
			print(char * counter, end='')
			for j in range(i + 1, N + 1):
				print(j, end=' ')
			counter -= 2
			char = str(int(char) - 1) + ' '
			print()
		char = str(2) + ' '
		counter = 3
		for i in range(2, N + 1):
			for j in range(N, i, -1):
				print(j, end=' ')
			print(char * counter, end='')
			for j in range(i + 1, N + 1):
				print(j, end=' ')
			char = str(int(char) + 1) + ' '
			counter += 2
			print()


class Solution:

	def printTriangle(self, N):
		for row in range(0, 2 * N - 1):
			for col in range(0, 2 * N - 1):
				(top, bottom) = (row, 2 * (N - 1) - row)
				(left, right) = (col, 2 * (N - 1) - col)
				print(N - min(min(top, bottom), min(left, right)), end=' ')
			print('\r')