Check if a point having maximum X and Y coordinates exists or not | Python3 program for the above approach ; Initialize INF as inifnity ; Function to return the pohaving maximum X and Y coordinates ; Base Case ; Stores if valid poexists ; If poarr [ i ] is valid ; Check for the same point ; Check for a valid point ; If current pois the required point ; Otherwise ; Function to find the required point ; Stores the powith maximum X and Y - coordinates ; If no required poexists ; Driver Code ; Given array of points ; Function Call
import sys NEW_LINE INF = sys . maxsize ; NEW_LINE def findMaxPoint ( arr , i , n ) : NEW_LINE INDENT if ( i == n ) : NEW_LINE INDENT return [ INF , INF ] NEW_LINE DEDENT flag = True ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( j == i ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT if ( arr [ j ] [ 0 ] >= arr [ i ] [ 0 ] or arr [ j ] [ 1 ] >= arr [ i ] [ 1 ] ) : NEW_LINE INDENT flag = False ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( flag ) : NEW_LINE INDENT return arr [ i ] ; NEW_LINE DEDENT return findMaxPoint ( arr , i + 1 , n ) ; NEW_LINE DEDENT def findMaxPoints ( arr , n ) : NEW_LINE INDENT ans = findMaxPoint ( arr , 0 , n ) ; NEW_LINE if ( ans [ 0 ] == INF ) : NEW_LINE INDENT print ( - 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " ( " , ans [ 0 ] , " ▁ " , ans [ 1 ] , " ) " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ [ 1 , 2 ] , [ 2 , 1 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 5 , 5 ] ] ; NEW_LINE N = len ( arr ) ; NEW_LINE findMaxPoints ( arr , N ) ; NEW_LINE DEDENT