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 ; Given Input ; Function call
function largestAltitude ( L , B ) { if ( L > B ) { let temp = B ; B = L ; L = temp ; } let low = 0 , high = L ; let res = 0 ; while ( low <= high ) { let mid = Math . floor ( low + ( high - low ) / 2 ) ; if ( mid <= Math . floor ( B / 2 ) ) { res = mid ; low = mid + 1 ; } else high = mid - 1 ; } return res ; } let L = 3 ; let B = 4 ; document . write ( largestAltitude ( L , B ) ) ;