Find any two pairs ( a , b ) and ( c , d ) such that a d | Java implementation to sort the array of points by its distance from the given point ; Function to find two pairs ( a , b ) and ( c , d ) such that a < c and b > d ; If no such pair is found ; Driver code
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void findPair ( pair arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int a = arr [ i ] . first , b = arr [ i ] . second ; for ( int j = i + 1 ; j < N ; j ++ ) { int c = arr [ j ] . first , d = arr [ j ] . second ; if ( a < c && b > d ) { System . out . println ( " ( " + a + " ▁ " + b + " ) , ▁ ( " + c + " ▁ " + d + " ) " ) ; return ; } } } System . out . println ( " NO ▁ SUCH ▁ PAIR ▁ EXIST " ) ; } public static void main ( String [ ] args ) { pair arr [ ] = { new pair ( 3 , 7 ) , new pair ( 21 , 23 ) , new pair ( 4 , 13 ) , new pair ( 1 , 2 ) , new pair ( 7 , - 1 ) } ; findPair ( arr , 5 ) ; } }