Check if a point having maximum X and Y coordinates exists or not | Java program for the above approach ; Initialize INF as inifnity ; Function to return the point having maximum X and Y coordinates ; Base Case ; Stores if valid point exists ; If point arr [ i ] is valid ; Check for the same point ; Check for a valid point ; If current point is the required point ; Otherwise ; Function to find the required point ; Stores the point with maximum X and Y - coordinates ; If no required point exists ; Driver Code ; Given array of points ; Function Call
import java . io . * ; class GFG { static int INF = Integer . MAX_VALUE ; static int [ ] findMaxPoint ( int arr [ ] [ ] , int i , int n ) { if ( i == n ) return new int [ ] { INF , INF } ; boolean flag = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( j == i ) continue ; if ( arr [ j ] [ 0 ] >= arr [ i ] [ 0 ] arr [ j ] [ 1 ] >= arr [ i ] [ 1 ] ) { flag = false ; break ; } } if ( flag ) return arr [ i ] ; return findMaxPoint ( arr , i + 1 , n ) ; } static void findMaxPoints ( int arr [ ] [ ] , int n ) { int ans [ ] = findMaxPoint ( arr , 0 , n ) ; if ( ans [ 0 ] == INF ) { System . out . println ( - 1 ) ; } else { System . out . println ( " ( " + ans [ 0 ] + " ▁ " + ans [ 1 ] + " ) " ) ; } } public static void main ( String [ ] args ) { int arr [ ] [ ] = new int [ ] [ ] { { 1 , 2 } , { 2 , 1 } , { 3 , 4 } , { 4 , 3 } , { 5 , 5 } } ; int N = arr . length ; findMaxPoints ( arr , N ) ; } }