JuniorMath

Construct the Rectangle

A web developer needs to know how to design a web page's size. Given a specific rectangular web page's area, design a rectangular web page whose length L and width W satisfy the following requirements:

  • The area of the rectangular web page you designed must equal the given target area.
  • The width W should not be larger than the length L, which means L >= W.
  • The difference between length L and width W should be as small as possible.

Return an array [L, W] where L and W are the length and width of the web page you designed, in sequence.

Example 1
Inputarea = 4
Output[2,2]
The target area is 4, and among the valid dimensions with L >= W, [2, 2] has the smallest difference between length and width.
Example 2
Inputarea = 37
Output[37,1]
Since 37 is prime, the only valid dimensions are L = 37 and W = 1.

Constraints

  • 1 <= area <= 10^7

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate