Consider a big party where N guests came to it and a log register for guest’s entry and exit times was maintained. Find the minimum time at which there were maximum guests at the party. Note that entries in the register are not in any order.
Note: Guests are leaving after the exit times.
Example 1:
Input:
N = 5
Entry= {1, 2,10, 5, 5}
Exit = {4, 5, 12, 9, 12}
Output: 3 5
Explanation: At time 5 there were 
             guest number 2, 4 and 5 present.
Example 2:
Input:
N = 7
Entry= {13, 28, 29, 14, 40, 17, 3}
Exit = {107, 95, 111, 105, 70, 127, 74}
Output: 7 40
Explanation: At time 40 there were 
             all 7 guests present in the party.
Your Task:
You don't need to read input or print anything. Your task is to complete the function findMaxGuests() which takes 3 arguments(Entry array, Exit array, N) and returns the maximum number of guests present at a particular time and that time as a pair.
Expected Time Complexity: O(N*Log(N) ).
Expected Auxiliary Space: O(1).
Constraints:
1 <= N <= 10^{5}
1 <= Entry[i],Exit[i] <= 10^{5}

Source: geeksforgeeks | Difficulty: MEDIUM
Tags: Sorting

Starter code: #User function Template for python3

class Solution:

    def findMaxGuests(self, Entry, Exit, N):
        # code here

Solutions:
class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		ans = 0
		count = 0
		data = []
		time = 0
		for i in range(N):
			data.append([Entry[i], 'x'])
			data.append([Exit[i], 'y'])
		data = sorted(data)
		for i in range(len(data)):
			if data[i][1] == 'x':
				count += 1
			if data[i][1] == 'y':
				count -= 1
			if ans < count:
				ans = count
				time = data[i][0]
		return (ans, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		guests_in = 1
		max_guests = 1
		max_time = Entry[0]
		i = 1
		j = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				guests_in += 1
				if max_guests < guests_in:
					max_guests = guests_in
					max_time = Entry[i]
				i += 1
			else:
				guests_in -= 1
				j += 1
		return (max_guests, max_time)


class Solution:

	def findMaxGuests(self, Entry, Exit, n):
		Entry.sort()
		Exit.sort()
		guests_in = 1
		max_guests = 1
		time = Entry[0]
		i = 1
		j = 0
		while i < n and j < n:
			if Entry[i] <= Exit[j]:
				guests_in += 1
				if guests_in > max_guests:
					max_guests = guests_in
					time = Entry[i]
				i += 1
			else:
				guests_in = guests_in - 1
				j = j + 1
		return [max_guests, time]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 0
		j = 0
		count = 0
		maxi = -1
		k = 0
		while i < N:
			if Entry[i] <= Exit[j]:
				count += 1
				if count > maxi:
					maxi = max(count, maxi)
					k = Entry[i]
				i += 1
			elif Exit[j] < Entry[i]:
				count -= 1
				j += 1
		return (maxi, k)


import bisect

class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		mx = 0
		for i in range(N):
			x = bisect.bisect(Entry, Exit[i])
			if x - i > mx:
				mx = x - i
				time = Entry[x - 1]
		return [mx, time]


class Solution:

	def findMaxGuests(self, entry, exit, N):
		entry.sort()
		exit.sort()
		(s_t, e_t) = (0, 0)
		(guests, max_guests, time) = (0, 0, 0)
		while s_t < N:
			if entry[s_t] <= exit[e_t]:
				guests += 1
				if guests > max_guests:
					max_guests = guests
					time = entry[s_t]
				s_t += 1
			else:
				guests -= 1
				e_t += 1
		return (max_guests, time)


class Solution:

	def findMaxGuests(self, entry, exit, n):
		entry.sort()
		exit.sort()
		count = 0
		i = 0
		j = 0
		ans = 0
		k = 0
		while i < n:
			if entry[i] <= exit[j]:
				count += 1
				if count > ans:
					ans = max(ans, count)
					k = entry[i]
				i += 1
			elif entry[i] > exit[j]:
				count -= 1
				j += 1
		return (ans, k)


import heapq

class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		guests = [(Entry[i], Exit[i]) for i in range(N)]
		guests.sort()
		pq = []
		ans = 0
		time = -1
		for i in range(N):
			while len(pq) > 0 and pq[0] < guests[i][0]:
				heapq.heappop(pq)
			heapq.heappush(pq, guests[i][1])
			if ans < len(pq):
				ans = len(pq)
				time = guests[i][0]
		return (ans, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		maxans = [0, 0]
		i = j = 0
		guests = 0
		while i < len(Entry) and j < len(Exit):
			if Entry[i] <= Exit[j]:
				guests += 1
				if guests > maxans[0]:
					maxans[0] = guests
					maxans[1] = Entry[i]
				i += 1
			else:
				guests -= 1
				j += 1
		return maxans


import heapq

class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		hp = []
		n = len(Entry)
		res = [0, 0]
		Entry.sort()
		Exit.sort()
		for i in range(n):
			curr_entry = Entry[i]
			while hp and hp[0][0] < curr_entry:
				heapq.heappop(hp)
			heapq.heappush(hp, (Exit[i], Entry[i]))
			if res[0] < len(hp):
				res = [len(hp), curr_entry]
		return res


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		res = []
		Entry.sort()
		Exit.sort()
		guest = 1
		max_gst = 1
		time = Entry[0]
		i = 1
		j = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				guest += 1
				if guest > max_gst:
					max_gst = guest
					time = Entry[i]
				i += 1
			else:
				guest -= 1
				j += 1
		res.append(max_gst)
		res.append(time)
		return res


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 0
		j = 0
		time = 0
		maxi = 0
		count = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				count += 1
				if count > maxi:
					maxi = count
					time = Entry[i]
				i += 1
			else:
				count -= 1
				j += 1
		return [maxi, time]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 0
		j = 0
		currentGuests = 0
		maxGuests = 0
		time = 0
		while i < N and j < N:
			if entry[i] <= exit[j]:
				currentGuests += 1
				if currentGuests > maxGuests:
					maxGuests = currentGuests
					time = entry[i]
				i += 1
			else:
				currentGuests -= 1
				j += 1
		return (maxGuests, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		A = [(v, 1) for v in Entry]
		A.extend([(v + 1, -1) for v in Exit])
		A.sort()
		(curtm, hc, mxhc, mntm) = (0, 0, 0, 0)
		for (tm, off) in A:
			if tm > curtm:
				if hc > mxhc:
					mxhc = hc
					mntm = curtm
				curtm = tm
			hc += off
		if hc > mxhc:
			mxhc = hc
			mntm = curtm
		return (mxhc, mntm)


import bisect

class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		arr = Entry.copy()
		dep = Exit.copy()
		arr.sort()
		dep.sort()
		count = 0
		mx = -9999999
		i = 0
		j = 0
		t = 0
		while i < N:
			if arr[i] <= dep[j]:
				count += 1
				if mx < count:
					t = arr[i]
					mx = max(mx, count)
				i += 1
			elif arr[i] > dep[j]:
				count -= 1
				j += 1
		return (mx, t)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		(ans, f) = (0, 0)
		j = 0
		for i in range(N):
			while Exit[j] < Entry[i]:
				j += 1
			d = i + 1 - j
			if d > f:
				f = d
				ans = Entry[i]
		return [f, ans]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		maxEntry = max(Entry)
		maxExit = max(Exit)
		count = [0] * (max(maxEntry, maxExit) + 2)
		for i in range(len(Entry)):
			count[Entry[i]] += 1
			count[Exit[i] + 1] -= 1
		(maxGuests, maxGuestsAt) = (-1, 0)
		curGuests = 0
		for i in range(len(count)):
			curGuests += count[i]
			if curGuests > maxGuests:
				maxGuests = curGuests
				maxGuestsAt = i
		return [maxGuests, maxGuestsAt]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		(guestsIn, maxGuests, maxGuestsAt) = (1, 1, Entry[0])
		(i, j) = (1, 0)
		while i < len(Entry) and j < len(Exit):
			if Entry[i] <= Exit[j]:
				guestsIn += 1
				if guestsIn > maxGuests:
					maxGuests = guestsIn
					maxGuestsAt = Entry[i]
				i += 1
			else:
				guestsIn -= 1
				j += 1
		return [maxGuests, maxGuestsAt]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		from typing import List
		Entry.sort()
		Exit.sort()
		(s, e, c, ans_t, max_c) = (1, 0, 1, Entry[0], 1)
		while s < N and e < N:
			if Entry[s] <= Exit[e]:
				s += 1
				c += 1
			else:
				e += 1
				c -= 1
			if max_c < c:
				max_c = c
				ans_t = Entry[s - 1]
		return [max_c, ans_t]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		lb = Entry
		lp = Exit
		lb.sort()
		lp.sort()
		lb.reverse()
		lp.reverse()
		i = len(lb) - 1
		c = len(lp) - 1
		soma = 0
		max = -1
		p = 0
		while i >= 0 and c >= 0:
			m = min(lb[i], lp[c])
			clb = 0
			while i >= 0 and lb[i] == m:
				clb += 1
				i -= 1
			clp = 0
			while c >= 0 and lp[c] == m:
				clp += 1
				c -= 1
			soma += clb
			if soma > max:
				max = soma
				p = m
			soma -= clp
		return (max, p)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		u = 0
		v = 0
		guests = 0
		max_guests = 0
		while u < len(Entry):
			if Entry[u] <= Exit[v]:
				guests += 1
				u += 1
				if guests > max_guests:
					max_guests = guests
					ans = Entry[u - 1]
			else:
				guests -= 1
				v += 1
		return [max_guests, ans]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		count = 0
		maxi = 0
		time = 0
		j = 0
		for i in range(N):
			count += 1
			if count > maxi:
				maxi = count
				time = Entry[i]
			while j < N and i < N - 1 and (Exit[j] < Entry[i + 1]):
				count -= 1
				j += 1
		return (maxi, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		ans = []
		Entry.sort()
		Exit.sort()
		guest_rn = 1
		max_gue = 1
		time = Entry[0]
		i = 1
		j = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				guest_rn += 1
				if guest_rn > max_gue:
					max_gue = guest_rn
					time = Entry[i]
				i += 1
			else:
				guest_rn -= 1
				j += 1
		ans.append(max_gue)
		ans.append(time)
		return ans


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		total = Entry + Exit
		entry = [[e, 'A'] for e in Entry]
		exit = [[e, 'B'] for e in Exit]
		total = entry + exit
		total.sort()
		c = 0
		m = 0
		t = -1
		for i in range(len(total)):
			if total[i][1] == 'A':
				c = c + 1
				if c > m:
					m = c
					t = total[i][0]
			else:
				c = c - 1
		return (m, t)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 1
		j = 0
		count = 1
		res = 1
		val = Entry[0]
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				i += 1
				count += 1
			else:
				j += 1
				count -= 1
			if res < count:
				res = count
				val = Entry[i - 1]
		return [res, val]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 0
		j = 0
		n = len(Entry)
		in_guests = 0
		max_guests = 0
		time = Entry[0]
		while i < n and j < n:
			if Entry[i] <= Exit[j]:
				in_guests += 1
				if max_guests < in_guests:
					max_guests = in_guests
					time = Entry[i]
				i += 1
			else:
				in_guests -= 1
				j += 1
		return [max_guests, time]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		h = [0] * (max(exit) + 2)
		for i in range(N):
			h[Entry[i]] += 1
			h[Exit[i] + 1] -= 1
		curr = 0
		ans = (0, -1)
		for i in range(max(exit) + 1):
			curr += h[i]
			h[i] = curr
			if h[i] > ans[0]:
				ans = (h[i], i)
		return ans


class Solution:

	def findMaxGuests(self, arr, dep, n):
		arr.sort()
		dep.sort()
		(curr, ans) = (1, 1)
		(i, j) = (1, 0)
		time = arr[0]
		while i < n and j < n:
			if arr[i] <= dep[j]:
				curr += 1
				if curr > ans:
					time = arr[i]
					ans = curr
				i += 1
			else:
				curr -= 1
				j += 1
		return [ans, time]


class Solution:

	def findMaxGuests(self, entry, exit, n):
		maxi = max(exit)
		arr = [0] * (maxi + 2)
		for i in range(n):
			arr[entry[i]] += 1
			arr[exit[i] + 1] += -1
		prefix = arr[0]
		for i in range(1, len(arr)):
			prefix += arr[i]
			arr[i] = prefix
		ind = 0
		maxi = arr[0]
		for i in range(1, len(arr)):
			if arr[i] > maxi:
				maxi = arr[i]
				ind = i
		return [maxi, ind]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		ma = 0
		cu = 0
		i = j = 0
		ti = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				cu += 1
				if ma < cu:
					ma = cu
					ti = Entry[i]
				i += 1
			else:
				j += 1
				cu -= 1
		return (ma, ti)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 1
		j = 0
		m = 1
		res = 1
		t = Entry[0]
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				m += 1
				if res < m:
					res = m
					t = Entry[i]
				i += 1
			else:
				m -= 1
				j += 1
		return (res, t)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		maxi = float('-inf')
		Entry.sort()
		Exit.sort()
		guest = 0
		p1 = 0
		p2 = 0
		while p1 < len(Entry):
			if Entry[p1] <= Exit[p2]:
				guest += 1
				if guest > maxi:
					maxi = guest
					time = Entry[p1]
				p1 += 1
			else:
				guest -= 1
				p2 += 1
		return (maxi, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		(l, r) = (0, 0)
		cnt = 0
		p_res = 0
		time_res = None
		while l < N and r < N:
			if Entry[l] <= Exit[r]:
				cnt += 1
				if cnt > p_res:
					p_res = cnt
					time_res = Entry[l]
				l += 1
			elif Entry[l] > Exit[r]:
				cnt -= 1
				r += 1
		return (p_res, time_res)


class Solution:

	def findMaxGuests(self, entry, exit, N):
		entry.sort()
		exit.sort()
		i = 0
		j = 0
		time = 0
		guest = 0
		maxi = 0
		res = None
		while i < N and j < N:
			if entry[i] <= exit[j]:
				guest += 1
				if guest > maxi:
					maxi = guest
					time = entry[i]
				i += 1
			else:
				guest -= 1
				j += 1
		return [maxi, time]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		res = float('-inf')
		i = 0
		j = 0
		g = 0
		restime = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				g += 1
				if g > res:
					res = g
					restime = Entry[i]
				i += 1
			else:
				g -= 1
				j += 1
		return [res, restime]


import bisect

class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		n = len(Entry)
		Entry.sort()
		Exit.sort()
		maxNum = -1
		res = -1
		for (indx, enter) in enumerate(Entry):
			exit_indx = bisect.bisect_left(Exit, enter)
			if indx - exit_indx + 1 > maxNum:
				maxNum = indx - exit_indx + 1
				res = enter
		return (maxNum, res)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		plat = 1
		Entry.sort()
		Exit.sort()
		max_time = Entry[0]
		res = 1
		i = 1
		j = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				plat += 1
				if plat > res:
					max_time = Entry[i]
					res = plat
				i += 1
			else:
				plat -= 1
				j += 1
		return [res, max_time]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		l = []
		for i in range(N):
			l.append([Entry[i], 0])
			l.append([Exit[i], 1])
		l.sort()
		c = 0
		m = 0
		for i in l:
			if i[1] == 0:
				c += 1
			else:
				c -= 1
			if c > m:
				m = c
				a = i[0]
		return [m, a]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 1
		j = 0
		res = 1
		curr = 1
		time = Entry[0]
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				curr += 1
				if curr > res:
					res = curr
					time = Entry[i]
				i += 1
			else:
				curr -= 1
				j += 1
		return (res, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 0
		j = 0
		arr = []
		maxpeople = 0
		timming = 0
		activepeople = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				activepeople += 1
				if maxpeople < activepeople:
					maxpeople = activepeople
					timming = Entry[i]
				i += 1
			elif Entry[i] >= Exit[j]:
				activepeople -= 1
				j += 1
		arr.append(maxpeople)
		arr.append(timming)
		return arr


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		mx = max(max(Entry), max(Exit))
		arr = [0] * (mx + 2)
		for i in range(N):
			arr[Entry[i]] += 1
			arr[Exit[i] + 1] -= 1
		curr = 0
		ans = float('-inf')
		for i in range(len(arr)):
			curr += arr[i]
			if curr > ans:
				ans = curr
				res = (ans, i)
		return res


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		d = {}
		for i in range(N):
			if Entry[i] not in d:
				d[Entry[i]] = 1
			else:
				d[Entry[i]] += 1
			if Exit[i] + 1 not in d:
				d[Exit[i] + 1] = -1
			else:
				d[Exit[i] + 1] -= 1
		key = sorted(d)
		for i in range(1, len(key)):
			d[key[i]] += d[key[i - 1]]
		maxi = -1
		for k in key:
			if d[k] > maxi:
				maxi = d[k]
				ans = [d[k], k]
		return ans


from heapq import heappush, heappop

class Solution:

	def findMaxGuests(self, entry, exit, n):
		ans = 0
		time = -1
		t = []
		for i in range(n):
			t.append([entry[i], exit[i]])
		t.sort()
		heap = []
		for i in range(n):
			while heap and heap[0] < t[i][0]:
				heappop(heap)
			heappush(heap, t[i][1])
			if len(heap) > ans:
				ans = len(heap)
				time = t[i][0]
		return (ans, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		dp = [0] * int(100000.0 + 2)
		for i in range(N):
			dp[Entry[i]] += 1
			dp[Exit[i] + 1] -= 1
		c = 0
		t = 0
		for i in range(1, len(dp)):
			dp[i] += dp[i - 1]
			if c < dp[i]:
				c = dp[i]
				t = i
		return [c, t]


class Solution:

	def findMaxGuests(self, entry, exit, n):
		entry.sort()
		exit.sort()
		time = 0
		guest = 0
		maxi = -999999
		i = 0
		j = 0
		while i < n and j < n:
			if entry[i] <= exit[j]:
				guest += 1
				if guest > maxi:
					time = entry[i]
					maxi = guest
				i += 1
			else:
				guest -= 1
				j += 1
		return [maxi, time]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry = sorted(Entry)
		Exit = sorted(Exit)
		i = 0
		j = 0
		maxi = 0
		addi = 0
		index = 0
		while i < N and j < N:
			en = Entry[i]
			dep = Exit[j]
			if en <= dep:
				addi += 1
				i += 1
			if dep < en:
				addi -= 1
				j += 1
			if addi > maxi:
				maxi = addi
				index = Entry[i - 1]
		return (maxi, index)


class Solution:

	def findMaxGuests(self, ent, ext, n):
		ent.sort()
		ext.sort()
		i = 0
		j = 0
		maxv = 0
		time = 0
		c = 0
		while i < n and j < n:
			if ent[i] <= ext[j]:
				c += 1
				if c > maxv:
					maxv = c
					time = ent[i]
				i += 1
			else:
				c -= 1
				j += 1
		l = [maxv, time]
		return l


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		(entry_i, exit_i) = (0, 0)
		max_guest = [0, 0]
		cnt = 0
		while entry_i < N:
			if exit_i == N or Entry[entry_i] <= Exit[exit_i]:
				cnt += 1
				if cnt > max_guest[0]:
					max_guest[0] = cnt
					max_guest[1] = Entry[entry_i]
				entry_i += 1
			else:
				cnt -= 1
				exit_i += 1
		return max_guest


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		maxs = 0
		count = 0
		i = 0
		j = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				count += 1
				i += 1
				if maxs < count:
					maxs = count
					ele = Entry[i - 1]
			else:
				count -= 1
				j += 1
		return (maxs, ele)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		if len(Exit) == 1:
			return [1, Entry[0]]
		Entry.sort(reverse=False)
		Exit.sort(reverse=False)
		i = 0
		j = 0
		maxcount = float('-inf')
		count = 0
		while i < len(Entry):
			if Entry[i] <= Exit[j]:
				count += 1
				if count > maxcount:
					maxcount = count
					time = Entry[i]
				i += 1
			else:
				count -= 1
				j += 1
		return [maxcount, time]


from heapq import *

class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		intervals = list(zip(Entry, Exit))
		intervals.sort()
		heap = list()
		ans = [0, 0]
		for (start, end) in intervals:
			while heap and heap[0] < start:
				heappop(heap)
			heappush(heap, end)
			if len(heap) > ans[0]:
				ans[0] = len(heap)
				ans[1] = start
		return (ans[0], ans[1])


class Solution:

	def findMaxGuests(self, start, end, N):
		m1 = max(start)
		m2 = max(end)
		arr = [0 for i in range(max(m1, m2) + 2)]
		for i in start:
			arr[i] += 1
		for j in end:
			arr[j + 1] += -1
		c = 0
		ms = 0
		time = 0
		for i in range(len(arr)):
			c += arr[i]
			if c > ms:
				ms = c
				time = i
		return [ms, time]


class Solution:

	def findMaxGuests(self, start, end, N):
		start.sort()
		end.sort()
		c = 1
		ms = 1
		i = 1
		j = 0
		time = start[0]
		while i < N and j < N:
			if start[i] <= end[j]:
				c += 1
				if c > ms:
					ms = c
					time = start[i]
				i += 1
			else:
				c -= 1
				j += 1
		return [ms, time]


class Solution:

	def findMaxGuests(self, Entry, Exit, n):
		Entry.sort()
		Exit.sort()
		max_logs = 1
		curr_log = 1
		pos = Entry[0]
		i = 1
		j = 0
		while i < n and j < n:
			if Entry[i] <= Exit[j]:
				curr_log += 1
				if curr_log > max_logs:
					pos = Entry[i]
					max_logs = curr_log
				i += 1
			else:
				curr_log -= 1
				j += 1
		return [max_logs, pos]


class Solution:

	def findMaxGuests(self, Entry, Exit, n):
		end = max(Exit) + 3
		count = [0] * end
		for i in range(n):
			count[Entry[i]] += 1
			count[Exit[i] + 1] -= 1
		max_ocrr = float('-inf')
		ans = 0
		for i in range(1, end):
			count[i] += count[i - 1]
			if count[i] > max_ocrr:
				max_ocrr = count[i]
				ans = i
		return [max_ocrr, ans]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		(i, j) = (0, 0)
		count = 0
		max_g = (0, 0)
		while i < len(Entry) and j <= len(Exit):
			if j == len(Exit) or Entry[i] <= Exit[j]:
				count += 1
				if count > max_g[0]:
					max_g = (count, Entry[i])
				i += 1
			else:
				count -= 1
				j += 1
		return max_g
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		entry = [int(x) for x in input().split()]
		exit = [int(x) for x in input().split()]
		solObj = Solution()
		ans = solObj.findMaxGuests(entry, exit, N)
		print(ans[0], ans[1])


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		guest_in = 1
		max_guest = 1
		time = Entry[0]
		i = 1
		j = 0
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				guest_in = guest_in + 1
				if guest_in > max_guest:
					max_guest = guest_in
					time = Entry[i]
				i = i + 1
			else:
				guest_in = guest_in - 1
				j = j + 1
		return (max_guest, time)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		entry = [int(x) for x in input().split()]
		exit = [int(x) for x in input().split()]
		solObj = Solution()
		ans = solObj.findMaxGuests(entry, exit, N)
		print(ans[0], ans[1])


class Solution:

	def findMaxGuests(self, entry, exit, n):
		entry.sort()
		exit.sort()
		res = []
		cnt = 0
		i = 0
		j = 0
		time = 0
		maxm = 0
		while i < n:
			if entry[i] <= exit[j]:
				cnt += 1
				if maxm < cnt:
					time = entry[i]
					maxm = cnt
				i += 1
			else:
				cnt -= 1
				j += 1
		return (maxm, time)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		entry = [int(x) for x in input().split()]
		exit = [int(x) for x in input().split()]
		solObj = Solution()
		ans = solObj.findMaxGuests(entry, exit, N)
		print(ans[0], ans[1])


class Solution:

	def findMaxGuests(self, arrl, exit, n):
		arrl.sort()
		exit.sort()
		guests_in = 1
		max_guests = 1
		time = arrl[0]
		i = 1
		j = 0
		while i < n and j < n:
			if arrl[i] <= exit[j]:
				guests_in = guests_in + 1
				if guests_in > max_guests:
					max_guests = guests_in
					time = arrl[i]
				i = i + 1
			else:
				guests_in = guests_in - 1
				j = j + 1
		return (max_guests, time)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		entry = [int(x) for x in input().split()]
		exit = [int(x) for x in input().split()]
		solObj = Solution()
		ans = solObj.findMaxGuests(entry, exit, N)
		print(ans[0], ans[1])


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		guests = []
		for i in range(N):
			guests.append([Entry[i], False])
			guests.append([Exit[i], True])
		guests.sort()
		maxgst = -1
		attgst = 0
		tmpgst = 0
		for i in range(len(guests)):
			if not guests[i][1]:
				attgst += 1
			else:
				attgst -= 1
			if attgst > maxgst:
				maxgst = attgst
				tmpgst = guests[i][0]
		return (maxgst, tmpgst)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		entry = [int(x) for x in input().split()]
		exit = [int(x) for x in input().split()]
		solObj = Solution()
		ans = solObj.findMaxGuests(entry, exit, N)
		print(ans[0], ans[1])


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		max_guests = 0
		c_time = -1
		temp_entry = Entry
		temp_entry.sort()
		Exit.sort()
		k = i = 0
		temp = 0
		while i < N:
			if temp_entry[i] <= Exit[k]:
				temp += 1
				if temp > max_guests:
					max_guests = temp
					c_time = temp_entry[i]
				i += 1
			else:
				k += 1
				temp -= 1
		return (max_guests, c_time)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		entry = [int(x) for x in input().split()]
		exit = [int(x) for x in input().split()]
		solObj = Solution()
		ans = solObj.findMaxGuests(entry, exit, N)
		print(ans[0], ans[1])


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		guests = 0
		max_guests_so_far = 0
		time = 0
		ptr_in = 0
		ptr_out = 0
		while ptr_in < N and ptr_out < N:
			if Entry[ptr_in] <= Exit[ptr_out]:
				guests += 1
				if guests > max_guests_so_far:
					max_guests_so_far = guests
					time = Entry[ptr_in]
				ptr_in += 1
			elif Entry[ptr_in] > Exit[ptr_out]:
				guests -= 1
				ptr_out += 1
		return (max_guests_so_far, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		{1, 2, 5, 5, 10}
		{4, 5, 9, 12, 12}
		Entry.sort()
		Exit.sort()
		(ent, ex) = (0, 0)
		(time, maxGuest) = (0, 0)
		curGuest = 0
		while ent < N:
			if Entry[ent] <= Exit[ex]:
				curGuest += 1
				if maxGuest < curGuest:
					maxGuest = curGuest
					time = Entry[ent]
				ent += 1
			else:
				curGuest -= 1
				ex += 1
		return (maxGuest, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		max_g = (0, 0)
		count = 0
		(i, j) = (0, 0)
		while i < len(Entry):
			if j >= len(Exit) or Entry[i] <= Exit[j]:
				count += 1
				if max_g[0] < count:
					max_g = (count, Entry[i])
				i += 1
			else:
				count -= 1
				j += 1
				if j == len(Exit):
					i += 1
		return max_g


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		cou = 1
		ma = 1
		time = Entry[0]
		i = 1
		j = 0
		while i < N and j < N:
			if Exit[j] >= Entry[i]:
				cou = cou + 1
				if ma < cou:
					ma = cou
					time = Entry[i]
				i = i + 1
			else:
				cou = cou - 1
				j = j + 1
		return [ma, time]


class Solution:

	def findMaxGuests(self, entry, exit, n):
		entry.sort()
		exit.sort()
		ptr1 = ptr2 = 0
		count1 = 0
		maxcount = 0
		ans = 0
		while ptr1 < n and ptr2 < n:
			if entry[ptr1] <= exit[ptr2]:
				count1 += 1
				if count1 > maxcount:
					maxcount = count1
					ans = entry[ptr1]
				ptr1 += 1
			else:
				count1 -= 1
				ptr2 += 1
		return [maxcount, ans]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 1
		j = 0
		g_in = 1
		max_guest = 1
		time = Entry[0]
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				g_in = g_in + 1
				if max_guest < g_in:
					max_guest = g_in
					time = Entry[i]
				i = i + 1
			else:
				g_in = g_in - 1
				j = j + 1
		return (max_guest, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		from collections import Counter
		c1 = dict(Counter(Entry))
		c2 = dict(Counter(Exit))
		keys = set(list(c1.keys()) + list(c2.keys()))
		keys = sorted(keys, key=lambda x: x)
		s = 0
		max_s = 0
		for k in keys:
			if k in c1:
				s += c1[k]
			if s > max_s:
				max_s = s
				ans = (s, k)
			if k in c2:
				s -= c2[k]
		return ans


from collections import Counter

class Solution:

	def findMaxGuests(self, entry, exit, n):
		start = min(entry)
		end = max(exit)
		countIn = Counter(entry)
		countOut = Counter(exit)
		curr = global_max = 0
		time = 0
		for t in range(start, end + 1):
			curr = curr + countIn[t] - countOut[t - 1]
			if curr > global_max:
				global_max = curr
				time = t
		return (global_max, time)


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		time = Entry[0]
		guest = 1
		i = 1
		j = 0
		curguest = 1
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				curguest += 1
				if curguest > guest:
					guest = curguest
					time = Entry[i]
				i += 1
			else:
				curguest -= 1
				j += 1
		return (guest, time)


class Solution:

	def findMaxGuests(self, entry, exit, N):
		entry.sort()
		exit.sort()
		i = 0
		j = 0
		res = 1
		curr = 0
		minTime = entry[0]
		while i < N and j < N:
			if entry[i] <= exit[j]:
				curr += 1
				i += 1
			else:
				curr -= 1
				j += 1
			if curr > res:
				res = curr
				minTime = entry[i - 1]
		return [res, minTime]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		ent = sorted(Entry)
		exit = sorted(Exit)
		i = 1
		j = 0
		curr = 1
		res = 1
		min_time = ent[0]
		li = []
		while i < N and j < N:
			if ent[i] <= exit[j]:
				curr += 1
				i += 1
			else:
				curr -= 1
				j += 1
			if res < curr:
				res = curr
				min_time = ent[i - 1]
		li.append(res)
		li.append(min_time)
		return li


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		i = 0
		j = 0
		p = 0
		t = 0
		m = 0
		arr = []
		while i < len(Exit) and i >= j:
			l = i
			if Entry[i] <= Exit[j]:
				p += 1
				i += 1
			else:
				p -= 1
				j += 1
			if m < p:
				m = p
				t = Entry[l]
		return [m, t]


class Solution:

	def findMaxGuests(self, Entry, Exit, N):
		Entry.sort()
		Exit.sort()
		guests = 1
		max_guests = 1
		time = Entry[0]
		(i, j) = (1, 0)
		while i < N and j < N:
			if Entry[i] <= Exit[j]:
				guests += 1
				if max_guests < guests:
					max_guests = guests
					time = Entry[i]
				i += 1
			else:
				guests -= 1
				j += 1
		return (max_guests, time)