While solving This algorithm problem I was unable to come up with condition for the collision to occur ( other than the naive O(n^2) algorithm ) on reading the explanation they say
Let’s deepen the observation. For a set of people with the same y coordinate, let’s consider “in what condition does a collision occurs?” Then we can see that a collision occurs if and only if the following two people collides: the leftmost person facing right, and the rightmost person facing left. In other words, among the people with the same y coordinate, all the people except for the two mentioned above is unimportant.
I am unable to understand how the two people who are at extremes of some y=k
satisfy the condition it is quite possible that the two at extremes of this y=k
face the same direction and there could exist some pair in between these extremes that satisfy the condition, can you help me understand if I'm wrong in understanding the solution?