Check if a point having maximum X and Y coordinates exists or not | C # 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
using System ; class GFG { static void findMaxPoint ( int [ , ] arr ) { int maxX = int . MinValue ; int maxY = int . MinValue ; int n = arr . GetLength ( 0 ) ; 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 ] ) { Console . WriteLine ( " ( " + maxX + " , ▁ " + maxY + " ) " ) ; return ; } } Console . WriteLine ( - 1 ) ; } public static void Main ( String [ ] args ) { int [ , ] arr = new int [ , ] { { 1 , 2 } , { 2 , 1 } , { 3 , 4 } , { 4 , 3 } , { 5 , 5 } } ; findMaxPoint ( arr ) ; } }