educative.io

The suggested overlap checking method is over complicated

Would love for the author to revisit this course and update the content more frequently. An obviously more reasonable check would be

def overlap(interval_a, interval_b) -> bool:
  return max(interval_a[0], interval_b[0]) <= min(interval_a[1], interval_b[1])

Without knowing how the intervals overlap, a condition must be met is: the start of the overlapped interval must be smaller or equal to its end.


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Intervals Intersection (medium) - Grokking the Coding Interview: Patterns for Coding Questions

Hi @Hiep_Doan
Thank you for your suggestion regarding the betterment of code. We’ll look into it. Your feedback is much appreciated!