Altitude of largest Triangle that can be inscribed in a Rectangle

Given a rectangle of length L and breadth B, the task is to print the maximum integer altitude possible of the largest triangle that can be inscribed in it, such that the altitude of the triangle should be equal to half of the base.Examples:Input: L = 3, B = 4Output: 2Input: L = 8, B = 9Output: 4Input: L = 325, B = 300Output: 162Naive Approach: The simplest approach is to iterate over the range [0, min(L, B)] in reverse and if the current value is less than or equal to max(L, B) / 2, then print the current value as the answer and break the loop.Time Complexity: O(min(L, B))Auxiliary Space: O(1)Binary Search Approach: The above approach can be optimized by using the Binary Search technique and observing the fact that it is always optimal to select the base of the triangle on the side with a maximum side length of the rectangle. Follow the steps below to solve the problem:If  L is larger than B, then swap the values.Initialize three variables, say, low as 0, and high as L to perform the binary search on the range [0, L].Also, initialize a variable, say res as 0 to store the maximum possible length of the altitude.Iterate while low is less than or equal to high and perform the following steps:Initialize a variable, say mid, and set it to low + (high – low) / 2.If the value of mid ≤ B / 2, then assign mid to res and mid +1 to low.Otherwise, set high to mid – 1.Finally, after completing the above steps, print the value obtained in res.Below is the implementation of the above approach:C++#include using namespace std;  int largestAltitude(int L, int B){        if (L > B) {        swap(B, L);    }              int low = 0, high = L;              int res = 0;              while (low