Given two segments [L1, R1] and [L2, R2], the task is to choose two elements x and y from both the ranges (one from range one and other from range two) such that no element belongs to both the ranges i.e. x belongs to first range and y belongs to second range. If no such element exists then print -1 instead.
Input: L1 = 1, R1 = 6, L2 = 3, R2 = 11
Output: 1 11
1 lies only in range [1, 6] and 11 lies only in [3, 11]
Input: L1 = 5, R1 = 10, L2 = 1, R2 = 7
Output: 1 10
- If L1 != L2 and R1 != R2 then the points will be min(L1, L2) and max(R1, R2).
- Else only one point can be chosen from one of the ranges as one of the range is completely inside the other so we print -1 for that point.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Minimum change in given value so that it lies in all given Ranges
- P - smooth numbers in given ranges
- Number of intersections between two ranges
- Count Primes in Ranges
- Find if it is possible to get a ratio from given ranges of costs and quantities
- Count distinct median possible for an Array using given ranges of elements
- Queries for maximum difference between prime numbers in given ranges
- Print matrix after applying increment operations in M ranges
- Minimum removals required to make ranges non-overlapping
- Check whether the point (x, y) lies on a given line
- Check whether a given point lies on or inside the rectangle | Set 3
- Find a point that lies inside exactly K given squares
- Check whether a given point lies inside a triangle or not
- How to check if a given point lies inside or outside a polygon?
- Find if a point lies inside a Circle
- Sort an Array of Points by their distance from a reference Point
- Steps required to visit M points in order on a circular ring of N points
- Prime points (Points that split a number into two primes)
- Reflection of a point at 180 degree rotation of another point
- Number of Integral Points between Two Points
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.