Find all groups that meets the condition

23 Views Asked by At

I have $n$ elements, each of them have two unsigned int attributes $x$ and $y$.

Now I'd like to find out all the groups that fit the following condition:

$A.x \geq B.y$ and $B.x \geq A.y$.

The groups can be a number of $2$,$3, \ldots n$. For example, $A,B,C$ can meet this requirement with each other, so this forms a group of $3$.

How to find them efficiently?