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
- Find missing elements of a range
- Count distinct median possible for an Array using given ranges of elements
- Missing even and odd elements from the given arrays
- Find k-th smallest element in given n ranges
- Find if there exists a direction for ranges such that no two range intersect
- Find the missing value from the given equation a + b = c
- Missing occurrences of a number in an array such that maximum absolute difference of adjacent elements is minimum
- Find first k natural numbers missing in given array
- Find the missing number in unordered Arithmetic Progression
- Find elements larger than half of the elements in an array
- Find all elements in array which have at-least two greater elements
- Find Kth element in an array containing odd elements first and then even elements
- Search an element in given N ranges
- Products of ranges in an array
- Compress the array into Ranges
- Count Primes in Ranges
- GCDs of given index ranges in an array
- Maximum occurred integer in n ranges | Set-2
- Data Type Ranges and their macros in C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.