You will be given N number of strings. You have to find the lexicographically smallest string and the lexicographically largest string among these strings.
Example 1:
Input:
N = 3
strings = a , ab , abc
Output: a abc
Explanation: Lexicographically smallest is
"a" and lexicographically largest is
"abc".
 
Example 2:
Input:
N = 2
strings = abc , abc
Output: abc abc
Explanation: Lexicographically smallest is
"abc" and lexicographically largest is
"abc"
 
Your Task:  
You dont need to read input or print anything. Complete the function orderStringÃ¢â¬â¹() which takes a 2d character array and an integer N as input parameter and returns an array of size 2 where first value should be lexicographically smallest string and second value should be lexicographically largest string.
 
Expected Time Complexity: O(N* max of all string length ).
Expected Auxiliary Space: O(1).
 
Constraints:
1 <= N , length of each string <= 10^{3}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:
    def orderString(self, s, n):
        # code here

Solutions:
class Solution:

	def orderString(self, s, n):
		return (min(s), max(s))


class Solution:

	def orderString(self, s, n):
		d = min(s)
		d1 = max(s)
		b = []
		b.append(d)
		b.append(d1)
		return b


class Solution:

	def orderString(self, s, n):
		s.sort()
		return (s[0], s[-1])


class Solution:

	def orderString(self, s, n):
		s = sorted(s)
		return [s[0], s[-1]]


class Solution:

	def orderString(self, s, n):
		mi = s[0]
		ma = s[0]
		for i in range(1, n):
			mi = min(mi, s[i])
			ma = max(ma, s[i])
		return (mi, ma)


class Solution:

	def orderString(self, s, n):
		k = min(s)
		p = max(s)
		return (k, p)


class Solution:

	def orderString(self, s, n):
		mini = 0
		maxi = 0
		for i in range(1, len(s)):
			if s[mini] > s[i]:
				mini = i
			elif s[maxi] < s[i]:
				maxi = i
		return (s[mini], s[maxi])


class Solution:

	def orderString(self, s, n):
		l = []
		si = 0
		bi = 0
		for i in range(n - 1):
			if s[si] >= s[i + 1]:
				si = i + 1
			if s[bi] <= s[i + 1]:
				bi = i + 1
		l.append(s[si])
		l.append(s[bi])
		return l


class Solution:

	def orderString(self, s, n):
		l = []
		l.append(min(s))
		l.append(max(s))
		return l


class Solution:

	def orderString(self, s, n):
		if n == 1:
			return [s[0], s[0]]
		s.sort()
		ans = []
		ans.append(s[0])
		ans.append(s[-1])
		return ans


class Solution:

	def orderString(self, s, n):
		mi = s[0]
		mx = s[0]
		for i in range(n):
			if s[i] > mx:
				mx = s[i]
			if s[i] < mi:
				mi = s[i]
		return (mi, mx)


class Solution:

	def orderString(self, s, n):
		mini = min(s)
		maxi = max(s)
		return (mini, maxi)


class Solution:

	def orderString(self, s, n):
		li = []
		for i in range(len(s)):
			li.append(s[i])
		li.sort()
		return (li[0], li[-1])


class Solution:

	def orderString(self, s, n):
		l1 = []
		l = sorted(s)
		l1.append(l[0])
		l1.append(l[len(l) - 1])
		return l1


class Solution:

	def orderString(self, s, n):
		mini = s[0]
		maxi = s[0]
		for i in s:
			if i < mini:
				mini = i
			elif i > maxi:
				maxi = i
		return (mini, maxi)


class Solution:

	def orderString(self, s: list, n: int) -> tuple:
		minimum = s[0]
		maximum = s[0]
		for i in range(n):
			if s[i] < minimum:
				minimum = s[i]
			if s[i] > maximum:
				maximum = s[i]
		return (minimum, maximum)


class Solution:

	def orderString(self, s, n):
		l = list(s)
		l.sort()
		return (l[0], l[n - 1])


class Solution:

	def orderString(self, s, n):
		if n == 1:
			return (s[0], s[0])
		minStr = s[0] if s[0] < s[1] else s[1]
		maxStr = s[0] if s[0] > s[1] else s[1]
		for i in range(2, n):
			if s[i] < minStr:
				minStr = s[i]
			if s[i] > maxStr:
				maxStr = s[i]
		return (minStr, maxStr)


class Solution:

	def orderString(self, s, n):
		b = sorted(s)
		c = []
		c.append(b[0])
		c.append(b[n - 1])
		return c


class Solution:

	def orderString(self, s, n):
		s = sorted(s)
		arr = []
		arr.append(s[0])
		arr.append(s[n - 1])
		return arr


class Solution:

	def orderString(self, s, n):
		m = s[0]
		l = []
		flag = 0
		for i in range(1, n):
			f = len(m)
			t = len(s[i])
			if f <= t:
				for j in range(f):
					if m[j] < s[i][j]:
						break
					elif m[j] > s[i][j]:
						m = s[i]
						break
			else:
				for j in range(t):
					if m[j] < s[i][j]:
						flag = 0
						break
					elif m[j] > s[i][j]:
						flag = 0
						m = s[i]
						break
					else:
						flag = 1
				if flag == 1:
					m = s[i]
		l.append(m)
		m = s[0]
		for i in range(1, n):
			f = len(m)
			t = len(s[i])
			if f <= t:
				for j in range(f):
					if m[j] < s[i][j]:
						m = s[i]
						flag = 0
						break
					elif m[j] > s[i][j]:
						flag = 0
						break
					else:
						flag = 1
				if flag == 1:
					m = s[i]
			else:
				for j in range(t):
					if m[j] < s[i][j]:
						m = s[i]
						break
					elif m[j] > s[i][j]:
						break
		l.append(m)
		return l


class Solution:

	def orderString(self, s, n):
		return [min(s), max(s)]
if __name__ == '__main__':
	T = int(input())
	for tcs in range(T):
		n = int(input())
		s = input().split()
		ob = Solution()
		ans = ob.orderString(s, n)
		print(ans[0], ans[1])


class Solution:

	def orderString(self, s, n):
		r = []
		s.sort()
		r.append(s[0])
		r.append(s[-1])
		return r
if __name__ == '__main__':
	T = int(input())
	for tcs in range(T):
		n = int(input())
		s = input().split()
		ob = Solution()
		ans = ob.orderString(s, n)
		print(ans[0], ans[1])


class Solution:

	def orderString(self, s, n):
		s.sort()
		l1 = []
		l1.append(s[0])
		l1.append(s[-1])
		return l1


class Solution:

	def orderString(self, s, n):
		strings = []
		for a in s:
			strings.append(a)
		return (min(strings), max(strings))


class Solution:

	def orderString(self, s, n):
		res = [''] * 2
		new = sorted(s)
		res[0] = new[0]
		res[1] = new[-1]
		return res


class Solution:

	def orderString(self, s, n):
		min_ = min(s)
		max_ = max(s)
		return [min_, max_]


class Solution:

	def orderString(self, s, n):
		small = s[0]
		large = s[0]
		ans = []
		for i in range(n):
			if s[i] >= large:
				large = s[i]
		for i in range(n):
			if s[i] <= small:
				small = s[i]
		ans.append(small)
		ans.append(large)
		return ans