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
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define N  5 NEW_LINE #define P  2 NEW_LINE void findMaxPoint ( int arr [ N ] [ P ] ) { int maxX = INT_MIN ; int maxY = INT_MIN ; int n = N ; for ( int i = 0 ; i < n ; i ++ ) { maxX = max ( maxX , arr [ i ] [ 0 ] ) ; maxY = max ( maxY , arr [ i ] [ 1 ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( maxX == arr [ i ] [ 0 ] && maxY == arr [ i ] [ 1 ] ) { cout << " ( " << maxX << " , ▁ " << maxY << " ) " ; return ; } } cout << ( -1 ) ; } int main ( ) { int arr [ N ] [ P ] = { { 1 , 2 } , { 2 , 1 } , { 3 , 4 } , { 4 , 3 } , { 5 , 5 } } ; findMaxPoint ( arr ) ; }