I am not able to find the reason for the last test case i.e a=100 and b=100, the minimal area of square=40000, so why not 20164 is minimal. My code is not able to run for last test case.

The dimension of each rectangle is 100 × 100. We need to stick them together so that we get a single large rectangle of dimension 200 × 100. To enclose this in a square, the largest side of the rectangle must be one of the sides of the square. But we know that all sides of a square are equal. Therefore, the dimension of the square which encloses the large rectangle must be 200 × 200.
The area of a square is given by the formula s^2 where s is the length of the side. Thus, the area of the square is 200^2 = 40000.


Thanks @anon53253486, people like you motivate to continue. Thanks buddy.

1 Like

So the basic logic for this problem if to first find the smaller side(<=) of the given reactangle(e.g if sides are a and b, and if a<=b).
Then double the smaller side (i.e 2a). Now the side of the square will be the smaller(<=) between (2a and b).

Glad you liked it :slight_smile: . If you understand C++, you can go through my code.