educative.io

Educative

A better overlap check?

Instead of using two condition with ‘or’ to check the overlapping:
if ((arr1[i].start >= arr2[j].start && arr1[i].start <= arr2[j].end) || (arr2[j].start >= arr1[i].start && arr2[j].start <= arr1[i].end))
I believe, we can use this single condition:
if (arr1[i].end >= arr2[j].start && arr1[i].start <= arr2[j].end)
Correct me if I am wrong, but I think this single condition covers all the overlapping cases.

Hey @Mustafa1,

Your solution seems fine.

Happy learning :slight_smile: