Length and Breadth of rectangle such that ratio of Area to diagonal ^ 2 is maximum | function to print length and breadth ; sort the input array ; create array vector of integers occurring in pairs ; push the same pairs ; calculate length and breadth as per requirement ; check for given condition ; print the required answer ; Driver Code
def findLandB ( arr , n ) : NEW_LINE INDENT arr . sort ( reverse = False ) NEW_LINE arr_pairs = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if ( arr [ i ] == arr [ i + 1 ] ) : NEW_LINE INDENT arr_pairs . append ( arr [ i ] ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT length = arr_pairs [ 0 ] NEW_LINE breadth = arr_pairs [ 1 ] NEW_LINE size = len ( arr_pairs ) NEW_LINE for i in range ( 1 , size - 1 ) : NEW_LINE INDENT if ( ( int ( length / breadth ) + int ( breadth / length ) ) > ( int ( arr_pairs [ i ] / arr_pairs [ i - 1 ] ) + int ( arr_pairs [ i - 1 ] / arr_pairs [ i ] ) ) ) : NEW_LINE INDENT length = arr_pairs [ i ] NEW_LINE breadth = arr_pairs [ i - 1 ] NEW_LINE DEDENT DEDENT print ( length , " , " , breadth ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 2 , 2 , 2 , 5 , 6 , 5 , 6 , 7 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE findLandB ( arr , n ) NEW_LINE DEDENT