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
- Find k-th smallest element in given n ranges
- Missing even and odd elements from the given arrays
- Find the missing value from the given equation a + b = c
- Find first k natural numbers missing in given array
- Find elements larger than half of the elements in an array
- Find all elements in array which have at-least two greater elements
- Products of ranges in an array
- Count Primes in Ranges
- Search an element in given N ranges
- Compress the array into Ranges
- GCDs of given index ranges in an array
- Data Type Ranges and their macros in C++
- Queries on probability of even or odd number in given ranges
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.