Given an integer array nums and two integers low and high, return True if every integer in the inclusive range [low, high] appears at least once in nums. Otherwise, return False.
nums is a one-dimensional array of integers (not an array of intervals). Duplicate values and values outside the range do not affect the answer.
Function Signature
def contains_range(nums: list[int], low: int, high: int) -> bool:
Constraints
-
0 <= len(nums) <= 10^5
-
-10^9 <= nums[i], low, high <= 10^9
-
low <= high
Examples
Input: nums = [1,2,3,4,5], low = 2, high = 4
Output: True
The values 2, 3 and 4 all appear in nums, so the range [2, 4] is fully covered.
Input: nums = [1,3,5,7], low = 1, high = 4
Output: False
The values 2 and 4 are missing from nums, so the range [1, 4] is not fully covered.
Input: nums = [4,2,2,9,3], low = 2, high = 4
Output: True
2, 3 and 4 each appear at least once. The repeated 2 and the out-of-range 9 change nothing, and the order of the array does not matter.