dsa · easy
Construct the Rectangle
You need a rectangle whose area (length × width) equals area. Length L and width W are positive integers with L >= W. Among all such pairs, choose the one that minimizes L - W (the most square-like fit). Return [L, W].
Arguments
area— required product of length and width
Example
area = 4. Possible pairs (L, W): (4, 1) difference 3, and (2, 2) difference 0. The closest pair is [2, 2].
area = 37 is prime, so the only pair is [37, 1].
Constraints
1 <= area <= 10^7
Examples
Example 1
Input: 4 Expected: [2,2]
Example 2
Input: 37 Expected: [37,1]