Given segments as ranges [L, R] where ranges are non-intersecting and non-overlapping. The task is to find all number between 1 to that doesn’t belong to any of the given ranges.
Input : N = 2, M = 6 Ranges: [1, 2] [4, 5] Output : 3, 6 Explanation: Only 3 and 6 are missing from the above ranges. Input : N = 1, M = 5 Ranges: [2, 4] Output : 1, 5
Approach: Given that we have ranges, which are non-overlapping and non-intersecting. First of all, sort all segments based on starting value. After sorting, iterate from each segment and find the numbers which are missing.
Below is the implementation of the above approach:
- Find the missing elements from 1 to M in given N ranges | Set-2
- Count distinct median possible for an Array using given ranges of elements
- Find k-th smallest element in given n ranges
- Find missing elements of a range
- Find if there exists a direction for ranges such that no two range intersect
- GCDs of given index ranges in an array
- Queries on probability of even or odd number in given ranges
- Search an element in given N ranges
- Maximum pair sum in the given index ranges of an Array
- Find first k natural numbers missing in given array
- Print matrix after applying increment operations in M ranges
- Count Primes in Ranges
- Products of ranges in an array
- Maximum occurred integer in n ranges | Set-2
- Queries to check if a number lies in N ranges of L-R
- Compress the array into Ranges
- Minimum removals required to make ranges non-overlapping
- Find the missing number in unordered Arithmetic Progression
- k-th missing element in an unsorted array
- Find the XOR of the elements in the given range [L, R] with the value K for a given set of queries
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.