Bird
0
0

Which of the following code snippets correctly checks if two time intervals (start1, end1) and (start2, end2) overlap?

easy📝 Conceptual Q12 of 15
LLD - Design — Hotel Booking System
Which of the following code snippets correctly checks if two time intervals (start1, end1) and (start2, end2) overlap?
Aif start1 < end2 and start2 < end1: overlap
Bif start1 > end2 or start2 > end1: overlap
Cif end1 <= start2 or end2 <= start1: no overlap
Dif start1 == end2 or start2 == end1: overlap
Step-by-Step Solution
Solution:
  1. Step 1: Understand time interval overlap condition

    Two intervals overlap if one starts before the other ends and vice versa.
  2. Step 2: Match condition to code

    Condition start1 < end2 and start2 < end1 correctly detects overlap.
  3. Final Answer:

    if start1 < end2 and start2 < end1: overlap -> Option A
  4. Quick Check:

    Overlap check = start1 < end2 and start2 < end1 [OK]
Quick Trick: Overlap if intervals cross each other in time [OK]
Common Mistakes:
  • Using <= instead of < causing false negatives
  • Confusing no overlap with overlap conditions
  • Checking equality as overlap incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes