Overlapping Intervals

You have been given the start and end times of 'N' intervals. Write a function to check if any two intervals overlap with each other.

Note :
If an interval ends at time T and another interval starts at the same time, they are not considered overlapping intervals.
Input format :
The first line contains an Integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.

The first line of each test case or query contains an integer 'N' representing the total number of intervals.

The second line contains 'N' single space-separated integers representing the starting time of the intervals. 

The third line contains 'N' single space-separated integers representing the end time of the intervals.
Output Format :
For each test case, return true if overlapping intervals are present. Otherwise, return false.

Output for every test case will be printed in a separate line.
Note :
You do not have to print anything. Just return the boolean value.
Constraints :
1 <= T <= 10^2
0 <= N <= 10^5
0 <= Start[i] <= 10^15
1 <= End[i] <= 10^15  

Time Limit: 1 sec
CodingNinjas
author
2y

It's the standard interval scheduling problem.

CodingNinjas
author
2y
Brute Force

Iterate over the intervals one by one.

For every interval, check if there is an overlap with any of the remaining intervals then we stop execution

Space Complexity: O(1)Explanation:

O(1)

Si...read more

CodingNinjas
author
2y
Sorting Approach

Sort the list of intervals first on the basis of their start time and then iterate through the array

If the start time of an interval is less than the end of the previous interval, the...read more

Add answer anonymously...
SAP Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter