Altitude of largest Triangle that can be inscribed in a Rectangle | Function to find the greatest altitude of the largest triangle triangle that can be inscribed in the rectangle ; If L is greater than B ; Variables to perform binary search ; Stores the maximum altitude possible ; Iterate until low is less than high ; Stores the mid value ; If mide is less than or equal to the B / 2 ; Update res ; Update low ; Update high ; Print the result ; Driver Code ; Given Input ; Function call
def largestAltitude ( L , B ) : NEW_LINE INDENT if ( L > B ) : NEW_LINE INDENT temp = B NEW_LINE B = L NEW_LINE L = temp NEW_LINE DEDENT low = 0 NEW_LINE high = L NEW_LINE res = 0 NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = low + ( high - low ) // 2 NEW_LINE if ( mid <= ( B / 2 ) ) : NEW_LINE INDENT res = mid NEW_LINE low = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT high = mid - 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L = 3 NEW_LINE B = 4 NEW_LINE print ( largestAltitude ( L , B ) ) NEW_LINE DEDENT