Geek is playing an array game. He is weak in the concepts of arrays. Geek is given two arrays arr[ ] and brr[ ] of the same size n. The array arr[ ] will be said to fit in array brr[ ] if by arranging the elements of both arrays, there exists a solution such that i'th element of arr[ ] is less than or equal to i'th element of brr[ ], for each i, 0 <= i < n. Help Geek find if the given array arr[ ] will fit in array brr[ ] or not.
Example 1:
Input: arr[] = {7, 5, 3, 2},
       brr[] = {5, 4, 8, 7} and n = 4
Output: YES
Explanation:
Transform arr[] = {2, 3, 5, 7} and
brr[] = {4, 5, 7, 8}.
Now, 2<=4, 3<=5, 5<=7 and 7<=8.
So arr[] array will fit in brr[] array.
Example 2:
Input: arr[] = {1, 2, 4},
       brr[] = {1, 2, 3} and n = 3 
Output: NO
Explanation: 
As 1<=1, 2<=2 but 4>3 so, 
arr[] array will not fit in brr[] array. 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function isFit() that takes an array arr[], another array brr[], size of the array n and returns true if array arr[ ] fit in array brr[ ] otherwise returns false. The driver code takes care of the printing.
Expected Time Complexity: O(N*log(N)).
Expected Auxiliary Space: O(1).
Constraints:
1 ≤ N ≤ 10^{5}
0 ≤ a[i], b[i] ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Sorting

Data structures

Mathematics

Starter code: #User function Template for python3



class Solution:

    def isFit (self,arr, brr, n) : 

        #Complete the function



Solutions:
class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		for i in range(n):
			if not arr[i] <= brr[i]:
				return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		c = 0
		arr.sort()
		brr.sort()
		for (i, j) in list(zip(arr, brr)):
			if i > j:
				c = c + 1
		if c == 0:
			return True
		else:
			return False


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		c = 0
		for i in range(n):
			if arr[i] <= brr[i]:
				c = c + 1
		if c == n:
			return True
		return False


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		flag = True
		for i in range(0, len(arr)):
			if brr[i] < arr[i]:
				flag = False
				break
		return flag


class Solution:

	def isFit(self, arr, brr, n):
		arr = sorted(arr)
		brr = sorted(brr)
		for i in range(n):
			if arr[i] > brr[i]:
				return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		arr = sorted(arr)
		brr = sorted(brr)
		res = 0
		for i in range(n):
			if arr[i] <= brr[i]:
				res += 1
		if res == n:
			return True
		else:
			return False


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		for index in range(n):
			if arr[index] > brr[index]:
				return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		i = 0
		while i < n:
			if arr[i] <= brr[i]:
				i += 1
			else:
				return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		ans = None
		arr.sort()
		brr.sort()
		for i in range(n):
			if arr[i] <= brr[i]:
				continue
			else:
				ans = False
				break
		else:
			ans = True
		return ans


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		return all((arr[i] <= brr[i] for i in range(n)))


class Solution:

	def isFit(self, arr, brr, n):
		m = []
		x = sorted(arr)
		y = sorted(brr)
		for i in range(len(arr)):
			if x[i] <= y[i]:
				m.append(True)
			else:
				m.append(False)
		if False in m:
			return False
		else:
			return True


class Solution:

	def isFit(self, arr, brr, n):
		x = 0
		a = sorted(arr)
		b = sorted(brr)
		for i in range(0, n):
			if a[i] <= b[i]:
				x += 1
		if x == n:
			return True
		else:
			return False


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		for i in range(n):
			if arr[i] > brr[i]:
				return 0
				break
		return 1


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		z = 0
		count = 0
		for i in arr:
			if i <= brr[z]:
				count += 1
			else:
				pass
			z += 1
		if count == n:
			return 1
		else:
			return 0


class Solution:

	def isFit(self, arr, brr, n):
		arr1 = sorted(arr)
		brr1 = sorted(brr)
		c = 0
		for i in range(n):
			if arr1[i] <= brr1[i]:
				c += 1
		if c == n:
			return True
		return False


class Solution:

	def isFit(self, arr, brr, n):
		arr = sorted(arr)
		brr = sorted(brr)
		x = [i for (i, j) in zip(arr, brr) if i > j]
		if x:
			return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		if [x for (x, y) in zip(arr, brr) if x > y]:
			return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		b = 0
		c = 0
		for i in range(len(arr)):
			if arr[i] > brr[i]:
				c += 1
			elif arr[i] <= brr[i]:
				b += 1
		if c > 0:
			return False
		else:
			return True


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		a = 0
		for (i, j) in zip(arr, brr):
			if i > j:
				return False
		return True


class Solution:

	def isFit(self, arr, brr, n):
		arr = sorted(arr)
		brr = sorted(brr)
		for i in range(0, len(arr)):
			if arr[i] > brr[i]:
				return 0
		return 1


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		f = 0
		for i in range(0, n):
			if arr[i] <= brr[i]:
				f = 1
			else:
				f = -1
				break
		if f == 1:
			return True
		else:
			return False


class Solution:

	def isFit(self, arr, brr, n):
		arr.sort()
		brr.sort()
		f1 = arr[0]
		f2 = arr[0]
		if f1 <= f2:
			for i in range(n):
				if arr[i] > brr[i]:
					return False
			return True
		else:
			for i in range(n):
				if arr[i] < brr[i]:
					return False
			return True


class Solution:

	def isFit(self, arr, brr, n):
		count = 0
		arr.sort()
		brr.sort()
		for i in range(len(arr)):
			if arr[i] <= brr[i]:
				count += 1
		if count == n:
			return True
		else:
			return False


class Solution:

	def isFit(self, a, b, n):
		a.sort()
		b.sort()
		for i in range(n):
			if a[i] > b[i]:
				return False
		return True