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
- Find Kth element in an array containing odd elements first and then even elements
- Search an element in given N ranges
- Count Primes in Ranges
- Products of ranges in an array
- Compress the array into Ranges
- Maximum occurred integer in n ranges | Set-2
- 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 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.