Construct the Rectangle

Problem Id: 492 Difficulty: Easy


Intuition

Solution


class Solution:
    def constructRectangle(self, area: int) -> List[int]:
        diff = area - 1
        ans = [area, 1]
        for i in range(1, int(math.sqrt(area)) + 1):
            if area % i != 0:
                continue
            if abs(area // i - i) < diff:
                ans = sorted([area // i, i], reverse=True)
        return ans