How to compare an element with other elements within an array efficiently for a condition
In the general form you present, you have $\Theta(n^2)$ things to compare so you need $\Omega(n^2)$ time. If you know more about the arrays or the comparison operator (e.g., the arrays are sorted and the comparison is $&lt;$ or $&gt;$) then you can probably do something better but, without more restrictions, there's no hope.