 So I was doing this problem on ad coder the other day called many segments and I learned this problem is about overlapping intervals and Through this problem. I actually learned a very cool trick about how to solve overlapping intervals and how to check if something's overlapping Without using any conditionals or just one conditional to be honest. So like let's say we have It's gone paint. Let's say we have some intervals. So what I mean by interval I mean it could be like a time that with a start and end it could be I don't know a line segment with a start and end so essentially anything that's like Like has like a start and an end, right? It could be a time. It could be like Like a start time and end time Anything like this, right? It could be on a number line. So let's say I have like an interval between one and five, right? So let's say we want to check and let's say I have another interval Let's say between two and six, right? So two and six So this would be two and six and this would be one of five Now In like some books to check if something's overlapping, right? So how would you do it if you wanted to check if something's overlapping, right? Well, what some people would do is they would check like the left most the left most boundaries to see if it's between The starting boundary For the one of them if it's greater than the left side of one of the starting boundaries and Smaller than the right side of the starting boundaries, right? And then you could do that that is a that is a way to do it to check for boundaries And I know I know some people they also check if like The right side of this boundaries between these two boundaries, right? Then that means they're overlapping, right? They're between The start and end time right these two intervals are between But here's a trick that you could do that I learned in this Add-coder problem is that all you have to do is just check if the maximum between the left boundaries, so the maximum of these Maximum of this boundary is smaller than or equal to the minimum of this boundary of the right boundary So in this case it would be the maximum. I'll just type it out here. It would be the max Whoops It would be the max between the left boundaries, which would be one and two Is the lesson or equal to the minimum of the right boundary, which would be five and six Okay, and the reason why this works is because if the maximum of one and two which would be two In this case this would be two here if it's smaller than or equal to minimum of the right boundaries The right boundary of the right boundaries of five and six is five. So since two is less than or equal to five That's overlapping and this works in most cases actually If you had like another interval, let's say we had here Let's say we had one and five And then we have another interval like two to three right So this this interval is overlapping, right? so if I were to check the max between The left boundaries, which is one and two so this max of one and two It would be two Right and two is smaller than or equal to the minimum of two and two and five That's between three and five of the right boundaries Right, so then that would be three Right the minimum between three and five is three and that's also overlapping right so that would be an overlapping interval also So yeah, as long as if you check the maximum of the left boundary is less than or equal to the minimum of the right boundaries This trick works regardless Okay, you don't have to do any of these conditionals of if if the left boundaries between left is greater than or equal to the left side of one interval and the Small and equal to the right side and if the right boundary is greater than or equal to the left boundaries and smaller than equal to the right one right the second one and you don't have to check if I don't know if The left boundary is equal to the left boundary and the right boundary is smaller than or equal To the right boundary like you don't need to do all this interval checking Yeah, so all you have to do is if I were to write this rewrite this again There's a cool trick you just have to do minute max of left Boundary bound is while equal to men of right bound. So yeah, that's just a That's it You that's the only if condition you need to check Then it's overlapping the two intervals overlap. Yeah, hope you guys enjoyed this video rate com subscribe This is a cool trick. I'll you see you guys later. Peace