Given an array arr[] containing positive elements. A and B are two numbers defining a range. The task is to check if the array contains all elements in the given range.
Example 1:
Input: N = 7, A = 2, B = 5
arr[] =  {1, 4, 5, 2, 7, 8, 3}
Output: Yes
Explanation: It has elements between 
range 2-5 i.e 2,3,4,5
Example 2:
Input: N = 7, A = 2, B = 6
arr[] = {1, 4, 5, 2, 7, 8, 3}
Output: No
Explanation: Array does not contain 6.
Your Task:
This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function check_elements() that takes array arr, integer N, integer A, and integer B  as parameters and returns the boolean True if array elements contain all elements in the given range else boolean False.
Note: If the array contains all elements in the given range then driver code outputs Yes otherwise, it outputs No
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1 ≤ N ≤ 10^{7}

Difficulty: EASY
Tags: Data structures

Complete search
Skill types: Data structures

Complete search
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Starter code:
class Solution:

    def check_elements(self, arr, n, A, B):

        # Your code goes here

        

Solutions:
class Solution:

	def check_elements(self, arr, n, A, B):
		present = True
		nums = [n for n in range(A, B + 1)]
		for num in nums:
			if num not in arr:
				present = False
				break
		return present


class Solution:

	def check_elements(self, arr, n, A, B):
		for i in range(A, B + 1):
			if i not in arr:
				return False
		return True


class Solution:

	def check_elements(self, arr, n, A, B):
		arr.sort()
		ans = []
		for i in range(A, B + 1):
			ans.append(i)
		return set(ans).intersection(set(arr)) == set(ans)


class Solution:

	def check_elements(self, arr, n, A, B):
		return_val = False
		for element in arr:
			abs_ele = abs(element)
			if abs_ele >= A and abs_ele < B or (abs_ele <= B and abs_ele > A) or (abs_ele == A and abs_ele == B):
				idx = abs_ele - A
				try:
					arr[idx] = -1 * arr[idx] if arr[idx] > 0 else arr[idx]
				except IndexError:
					continue
		expected_size = B - A + 1
		actual_size = 0
		for element in arr:
			if element < 0:
				actual_size += 1
			else:
				break
		if actual_size == expected_size:
			return_val = True
		return return_val


class Solution:

	def check_elements(self, arr, n, A, B):
		flag = False
		count = 0
		total_ele = B - A + 1
		arr = set(arr)
		for i in arr:
			if i >= A and i <= B:
				count += 1
				flag = True
		return count == total_ele


class Solution:

	def check_elements(self, arr, n, A, B):
		return set(range(A, B + 1)).issubset(set(arr))


class Solution:

	def check_elements(self, arr, n, A, B):
		remo = set((i for i in range(A, B + 1)))
		return set(remo).issubset(set(arr))


class Solution:

	def check_elements(self, arr, n, A, B):
		count = 0
		indices = [0] * (B - A + 1)
		for num in arr:
			if A <= num <= B:
				indices[num - A] = 1
		for index in indices:
			count += index
		return count == B - A + 1


class Solution:

	def check_elements(self, arr, n, A, B):
		return len(set((i for i in range(A, B + 1))).difference(set(a))) == 0


class Solution:

	def check_elements(self, arr, n, A, B):
		count = 0
		for i in set(arr):
			if A <= i <= B:
				count += 1
		if count == B - A + 1:
			return True
		else:
			return False


class Solution:

	def check_elements(self, arr, n, A, B):
		l = [i for i in range(A, B + 1)]
		l = set(l)
		k = l.copy()
		arr = set(arr)
		l = l.intersection(arr)
		if l == k:
			return True
		return False


class Solution:

	def check_elements(self, arr, n, A, B):
		arr = sorted(arr)
		s = set(arr)
		i = 0
		if A in arr:
			if B in arr:
				i = arr.index(A)
				while i < arr.index(B):
					if A in s:
						A = A + 1
						if A == B:
							return 1
					else:
						return 0
					i += 1
				return 1
			else:
				return 0
		else:
			return 0


class Solution:

	def check_elements(self, arr, n, A, B):
		if A > B:
			return False
		for i in range(A, B + 1):
			found = False
			for j in range(n):
				if arr[j] == i:
					found = True
					break
			else:
				return False
		return True


class Solution:

	def check_elements(self, arr, n, A, B):
		arr1 = set(arr)
		count = []
		for i in range(A, B + 1):
			count.append(i)
		k = 0
		for i in arr1:
			if i in count:
				k += 1
		if k != len(count):
			return False
		else:
			return True


class Solution:

	def check_elements(self, arr, n, A, B):
		l = [0] * (B - A + 1)
		for i in range(n):
			if arr[i] >= A and arr[i] <= B:
				l[arr[i] - A] = 1
		return sum(l) == B - A + 1


class Solution:

	def check_elements(self, arr, n, A, B):
		l = []
		for i in range(n):
			if arr[i] >= A and arr[i] <= B:
				l.append(arr[i])
		l1 = set(l)
		if len(l1) == B - A + 1:
			return True
		else:
			return False


class Solution:

	def check_elements(self, arr, n, a, b):
		f = []
		d = 0
		s = list(set(arr))
		for i in s:
			if i >= a and i <= b:
				f.append(i)
		for j in range(a, b + 1):
			d += j
		if sum(f) == d:
			return 1
		else:
			return 0


class Solution:

	def check_elements(self, arr, n, A, B):
		arr = set(arr)
		arr = list(arr)
		arr = sorted(arr)
		c = 0
		for i in range(len(arr)):
			if arr[i] >= A and arr[i] <= B:
				c += 1
		if c == B - A + 1:
			return True
		else:
			return False


class Solution:

	def check_elements(self, arr, n, A, B):
		arr.sort()
		for i in range(A, B + 1):
			if i not in arr:
				return 0
		return 1


class Solution:

	def check_elements(self, arr, n, A, B):
		arr_map = {el: 1 for el in arr}
		rl_c = 0
		f_c = 0
		for el in range(A, B + 1):
			rl_c += 1
			if arr_map.get(el):
				f_c += 1
		return f_c == rl_c


class Solution:

	def check_elements(self, arr, n, A, B):
		a = set()
		for i in range(n):
			if arr[i] >= A and arr[i] <= B:
				a.add(arr[i])
		if len(a) == B - A + 1:
			return True
		else:
			return False


class Solution:

	def check_elements(self, arr, n, A, B):
		arr = sorted(arr)
		for i in range(len(arr)):
			if arr[i] == A:
				A = A + 1
		if A > B:
			return 1
		return 0


class Solution:

	def check_elements(self, arr, n, A, B):
		count = 0
		for val in set(arr):
			if val >= A and val <= B:
				count += 1
		if count == B - A + 1:
			return True
		return False


class Solution:

	def check_elements(self, arr, n, A, B):
		l = B - A + 1
		arr = set(arr)
		sum1 = l * (A + B) // 2
		for i in arr:
			if i >= A and i <= B:
				sum1 -= i
		if sum1 == 0:
			return True
		return False


class Solution:

	def check_elements(self, arr, n, A, B):
		c = 0
		v = B - A + 1
		arr = set(arr)
		for i in range(A, B + 1):
			if i in arr:
				c += 1
			if c == v:
				return True
		return False


class Solution:

	def check_elements(self, arr, n, A, B):
		for i in range(n):
			if abs(arr[i]) >= A and abs(arr[i]) <= B:
				ind = abs(arr[i]) - A
				if ind < n and arr[ind] > 0:
					arr[ind] = -1 * arr[ind]
		B = B - A
		if B > n:
			return False
		for i in range(B + 1):
			if arr[i] > 0:
				return False
		return True


class Solution:

	def check_elements(self, arr, n, A, B):
		dic = {}
		for i in arr:
			dic[i] = dic.get(i, 0) + 1
		for i in range(A, B + 1):
			if dic.get(i) == None:
				return 0
			elif dic[i] > 0:
				continue
			else:
				return 0
		return 1


class Solution:

	def check_elements(self, arr, n, A, B):
		a1 = {'a', 'b'}
		for i in arr:
			if i >= A and i <= B:
				a1.add(i)
		a2 = {'a', 'b'}
		for i in range(A, B + 1):
			a2.add(i)
		if a1 == a2:
			return True
		return False


class Solution:

	def check_elements(self, arr, n, A, B):
		arr = set(arr)
		arr = list(arr)
		a = []
		b = []
		for i in range(A, B + 1):
			a.append(i)
		for j in range(len(arr)):
			if arr[j] in a:
				b.append(arr[j])
		if len(b) == len(a):
			return True
		else:
			return False


class Solution:

	def check_elements(self, arr, n, A, B):
		list1 = list(arr)
		list1.sort()
		flag = True
		for i in range(A, B + 1):
			if i in list1:
				flag = True
			else:
				flag = False
				break
		return flag


class Solution:

	def check_elements(self, arr, n, A, B):
		d = list(range(A, B + 1))
		return set(arr) & set(d) == set(d)


class Solution:

	def check_elements(self, arr, n, A, B):
		l = [x for x in range(A, B + 1)]
		if all((x in arr for x in l)):
			return True
		return False


class Solution:

	def check_elements(self, arr, n, A, B):
		c = 0
		for i in range(A, B + 1):
			if i not in arr:
				return False
				break
		else:
			return True


class Solution:

	def check_elements(self, arr, n, A, B):
		series = [x for x in range(A, B + 1)]
		for y in series:
			if y not in arr:
				return False
		return True