Math, Ternary Search
Given a cupboard. Assume that the width of the base is X. Then the Length of the base should not exceed (A−X) and the Height of the cupboard should not exceed (B−X). Also The Volume of the Cupboard should be maximum. You have to find minimum X which satisfies the given condition.
We know that the maximum volume of the cupboard will be X*(A-X)*(B-X). To find the required X we can do a Ternary Search on X in the range 1 to min(A,B).
The more popular solution for this question was to differentiate the above equation and solve for X to get the required answer.