

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find a range that covers all the elements of given N ranges in C++
Suppose we have a n ranges containing L and R. We have to check or find the index of 0 – based of the range which covers all the other given n – 1 ranges. If there is no such range, display -1. For example, if L = [2, 4, 3, 1], and R = [4, 6, 7, 9], then the output is 3. So it means the range at 3rd index (1 to 9) covers all the elements of other n – 1 ranges.
Since all L and R points are distinct, find the range of smallest L and largest R point, if both are the same range, then it indicates all other ranges lie within it. Otherwise it is not possible.
Example
#include<iostream> using namespace std; int fact (int n) { if (n == 0) return 1; return n * fact(n-1); } void showRange(int n) { int a = fact(n + 2) + 2; int b = a + n - 1; cout << "[" << a << ", " << b << "]"; } int main() { int n = 3 ; showRange(n); }
Output
[122, 124]
- Related Questions & Answers
- C++ program to find the best fit rectangle that covers a given point
- Find k-th smallest element in given n ranges in C++
- XOR of all the elements in the given range [L, R] in C++
- Find the kth element in the series generated by the given N ranges in C++
- Find the number of divisors of all numbers in the range [1, n] in C++
- Find missing elements of a range in C++
- Elements to be added so that all elements of a range are present in array in C++
- Find n positive integers that satisfy the given equations in C++
- JavaScript array: Find all elements that appear more than n times
- Count numbers in a range that are divisible by all array elements in C++
- Check if an array contains all elements of a given range in Python
- Count all possible N digit numbers that satisfy the given condition in C++
- Print all possible combinations of r elements in a given array of size n in C++
- Find permutation of first N natural numbers that satisfies the given condition in C++
- Find the largest interval that contains exactly one of the given N integers In C++
Advertisements