Given, N Mice and N holes are placed in a straight line. Each hole can accommodate only 1 mouse. A mouse can stay at his position, move one step right from x to x + 1, or move one step left from x to x -1. Any of these moves consumes 1 minute. Write a program to assign mice to holes so that the time when the last mouse gets inside a hole is minimized.
Note: Arrays M and H are the positions of the N mice and holes.
 
Example 1:
Input:
N = 3
M = {4, -4, 2}
H = {4, 0, 5}
Output:
4
Explanation:
If we assign mouse at 1st index to
the hole at 1st, mouse at 2nd index
to the hole at 2nd and the third to
the hole at third. Then, the maximum
time taken will be by the 2nd mouse,
i.e. 4-0 = 4 minutes.
Example 2:
Input:
N = 2
M = {4, 2}
H = {1, 7}
Output:
3
Explanation:
If we assign mouse at 1st index to
the hole at 2nd, and mouse at 2nd index
to the hole at 1st, the maximum
time taken will be by the 2nd mouse,
i.e. 7-4 = 3 minutes.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function assignMiceHoles() which takes an Integer N  and arrays M and H as input and returns the answer.
 
Expected Time Complexity: O(N*log(N))
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}
-10^{5 }<= M[i] , H[i] <= 10^{5}

Difficulty: EASY
Tags: Mathematics
Expected Time Complexity: O(N*log(N))
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:
    def assignMiceHoles(self, N , M , H):
        # code here

Solutions:
class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		ans = 0
		for i in range(N):
			ans = max(ans, abs(H[i] - M[i]))
		return ans


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		MH = list(zip(M, H))
		res = float('-inf')
		for x in MH:
			if res < abs(x[0] - x[1]):
				res = abs(x[0] - x[1])
		return res


class Solution:

	def assignMiceHoles(self, N, M, H):
		mice = sorted(M)
		holes = sorted(H)
		maxTime = 0
		for i in range(N):
			if abs(mice[i] - holes[i]) > maxTime:
				maxTime = abs(mice[i] - holes[i])
		return maxTime


class Solution:

	def assignMiceHoles(self, n, m, h):
		h.sort()
		m.sort()
		count = 0
		for i in range(n):
			count = max(count, abs(m[i] - h[i]))
		return count


class Solution:

	def assignMiceHoles(self, N, M, H):
		mx = -1
		M.sort()
		H.sort()
		for i in range(N):
			mx = max(mx, abs(M[i] - H[i]))
		return mx


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		maxi = float('-inf')
		for i in range(N):
			diff = abs(M[i] - H[i])
			maxi = max(maxi, diff)
		return maxi


import sys

class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		min_min = -sys.maxsize
		for i in range(N):
			min_min = max(abs(M[i] - H[i]), min_min)
		return min_min


class Solution:

	def assignMiceHoles(self, N, M, H):
		self.list1 = M
		self.list2 = H
		return max(list(map(lambda z: abs(z[0] - z[1]), list(zip(sorted(self.list1), sorted(self.list2))))))


class Solution:

	def assignMiceHoles(self, N, M, H):
		H.sort()
		M.sort()
		ans = 0
		for (a, b) in zip(H, M):
			ans = max(ans, abs(a - b))
		return ans


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		output = 0
		for i in range(N):
			if output < abs(M[i] - H[i]):
				output = abs(M[i] - H[i])
		return output


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		a = []
		for i in range(N):
			a.append(abs(M[i] - H[i]))
		return max(a)


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		res = []
		for i in range(0, N):
			d = abs(H[i] - M[i])
			res.append(d)
		return max(res)


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		ans = 0
		for (mice, pos) in zip(M, H):
			ans = max(abs(mice - pos), ans)
		return ans


import numpy as np

class Solution:

	def assignMiceHoles(self, N, M, H):
		h = np.array(sorted(H))
		m = np.array(sorted(M))
		diff = np.absolute(h - m)
		return max(diff)


class Solution:

	def assignMiceHoles(self, N, M, H):
		c = 0
		pos = 0
		M.sort()
		H.sort()
		for j in range(N):
			c = max(c, abs(H[j] - M[j]))
		return c


class Solution:

	def assignMiceHoles(self, N, M, H):
		cd = []

		def df(i, bc, v):
			if i < 0 or i >= len(H):
				cd.append(bc)
				return
			c = 0
			pos = 0
			M.sort()
			H.sort()
			for j in range(N):
				c = max(c, abs(H[j] - M[j]))
			return c
		d = df(0, [], [])
		return d


class Solution:

	def assignMiceHoles(self, N, M, H):
		M = sorted(M)
		H = sorted(H)
		Max = 0
		for i in range(len(M)):
			if Max < abs(M[i] - H[i]):
				Max = abs(M[i] - H[i])
		return Max
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		M = list(map(int, input().split()))
		H = list(map(int, input().split()))
		ob = Solution()
		print(ob.assignMiceHoles(N, M, H))


class Solution:

	def assignMiceHoles(self, N, M, H):
		H.sort()
		M.sort()
		ans = float('-inf')
		for i in range(N):
			ans = max(ans, abs(M[i] - H[i]))
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		M = list(map(int, input().split()))
		H = list(map(int, input().split()))
		ob = Solution()
		print(ob.assignMiceHoles(N, M, H))


class Solution:

	def assignMiceHoles(self, N, M, H):
		maxi = -1
		M.sort()
		H.sort()
		for i in range(N):
			maxi = max(abs(M[i] - H[i]), maxi)
		return maxi
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		M = list(map(int, input().split()))
		H = list(map(int, input().split()))
		ob = Solution()
		print(ob.assignMiceHoles(N, M, H))


class Solution:

	def assignMiceHoles(self, N, M, H):
		H.sort()
		M.sort()
		res = 0
		for x in range(N):
			res = max(res, abs(M[x] - H[x]))
		return res


class Solution:

	def assignMiceHoles(self, N, M, H):
		if len(M) != len(H):
			return -1
		M.sort()
		H.sort()
		res = 0
		for (i, j) in zip(M, H):
			res = max(res, abs(i - j))
		return res


class Solution:

	def assignMiceHoles(self, N, M, H):
		su = 0
		M = sorted(M)
		H = sorted(H)
		for i in range(0, len(M)):
			if abs(M[i] - H[i]) > su:
				su = abs(M[i] - H[i])
		return su


class Solution:

	def assignMiceHoles(self, N, M, H):
		M = sorted(M)
		H = sorted(H)
		ma = -100000000
		for i in range(len(M)):
			if abs(M[i] - H[i]) > ma:
				ma = abs(M[i] - H[i])
		return ma


import sys

class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		res = -sys.maxsize
		for (i, j) in zip(M, H):
			res = max(res, abs(i - j))
		return res


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		rmax = None
		for i in range(len(M)):
			tmp = abs(M[i] - H[i])
			if not rmax:
				rmax = tmp
			elif tmp > rmax:
				rmax = tmp
		return rmax


import heapq

class Solution:

	def assignMiceHoles(self, N, M, H):
		H.sort()
		M.sort()
		heap = []
		for (i, j) in zip(M, H):
			heapq.heappush(heap, -abs(i - j))
		return -heapq.heappop(heap)


class Solution:

	def assignMiceHoles(self, N, M, H):
		H.sort()
		M.sort()
		diff = abs(M[0] - H[0])
		for i in range(1, N):
			d = abs(M[i] - H[i])
			if d > diff:
				diff = d
		return diff


class Solution:

	def assignMiceHoles(self, N, M, H):
		if len(H) != len(M):
			return -1
		MAX = 0
		M.sort()
		H.sort()
		for i in range(N):
			if MAX < abs(M[i] - H[i]):
				MAX = abs(M[i] - H[i])
		return MAX


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		differences = [abs(M[i] - H[i]) for i in range(N)]
		return max(differences)


class Solution:

	def assignMiceHoles(self, n, m, h):
		m = sorted(m)
		h = sorted(h)
		res = -9999999999
		for i in range(n):
			res = max(res, abs(m[i] - h[i]))
		return res


class Solution:

	def assignMiceHoles(self, N, M, H):
		if len(M) != len(H):
			return -1
		m = sorted(M)
		h = sorted(H)
		max1 = 0
		for i in range(len(m)):
			if max1 < abs(m[i] - h[i]):
				max1 = abs(m[i] - h[i])
		return max1


import numpy as np

class Solution:

	def assignMiceHoles(self, N, M, H):
		m = np.array(M)
		h = np.array(H)
		m = np.sort(m)
		h = np.sort(h)
		max_t = 0
		for index in range(N):
			max_t = max(abs(m[index] - h[index]), max_t)
		return max_t


class Solution:

	def assignMiceHoles(self, N, M, H):
		M.sort()
		H.sort()
		ans = 0
		for i in range(len(M)):
			n = abs(M[i] - H[i])
			if n > 1:
				ans = max(n, ans)
		return ans


class Solution:

	def assignMiceHoles(self, n, m, h):
		m.sort()
		h.sort()
		t = -1
		for i in range(n):
			t = max(t, abs(m[i] - h[i]))
		return t


class Solution:

	def assignMiceHoles(self, n, m, h):
		m.sort()
		h.sort()
		t = -1
		for i in range(n):
			if m[i] < 0 and h[i] < 0 or (m[i] > 0 and h[i] > 0):
				t = max(t, abs(m[i] - h[i]))
			else:
				z = min(m[i], h[i])
				z = z * -1
				y = max(m[i], h[i])
				t = max(t, z + y)
		return t


class Solution:

	def assignMiceHoles(self, N, M, H):
		m = 0
		s = 0
		M = sorted(M, reverse=True)
		H = sorted(H, reverse=True)
		for x in range(N):
			s = abs(M[x] - H[x])
			m = max(m, s)
		return m