Check if a point having maximum X and Y coordinates exists or not | Initialize INF as infinity ; 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 ; Given array of points ; Function Call
let INF = Number . MAX_VALUE ; function findMaxPoint ( arr , i , n ) { if ( i == n ) return [ INF , INF ] ; let flag = true ; for ( let 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 ) ; } function findMaxPoints ( arr , n ) { let ans = findMaxPoint ( arr , 0 , n ) ; if ( ans [ 0 ] == INF ) { document . write ( - 1 ) ; } else { document . write ( " " + ans [ 0 ] + " " + ans [ 1 ] + " " ) ; } } let arr = [ [ 1 , 2 ] , [ 2 , 1 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 5 , 5 ] ] ; let N = arr . length ; findMaxPoints ( arr , N ) ;