Check if a point having maximum X and Y coordinates exists or not | Java program for the above approach ; Function to find the point having max X and Y coordinates ; Initialize maxX and maxY ; Length of the given array ; Get maximum X & Y coordinates ; Check if the required point i . e . , ( maxX , maxY ) is present ; If point with maximum X and Y coordinates is present ; If no such point exists ; Driver Code ; Given array of points ; Print answer
import java . io . * ; class GFG { static void findMaxPoint ( int arr [ ] [ ] ) { int maxX = Integer . MIN_VALUE ; int maxY = Integer . MIN_VALUE ; int n = arr . length ; for ( int i = 0 ; i < n ; i ++ ) { maxX = Math . max ( maxX , arr [ i ] [ 0 ] ) ; maxY = Math . max ( maxY , arr [ i ] [ 1 ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( maxX == arr [ i ] [ 0 ] && maxY == arr [ i ] [ 1 ] ) { System . out . println ( " ( " + maxX + " , ▁ " + maxY + " ) " ) ; return ; } } System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = new int [ ] [ ] { { 1 , 2 } , { 2 , 1 } , { 3 , 4 } , { 4 , 3 } , { 5 , 5 } } ; findMaxPoint ( arr ) ; } }