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
- 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
- Find first k natural numbers missing in given array
- Find elements larger than half of the elements in an array
- Find Kth element in an array containing odd elements first and then even elements
- Find all elements in array which have at-least two greater elements
- Products of ranges in an array
- Search an element in given N ranges
- Compress the array into Ranges
- Count Primes in Ranges
- 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.