Tap here to switch tabs
Problem
Submissions

Problem: Construct the Rectangle

med
30 min
Try to solve the Construct the Rectangle problem.

Statement

A web developer needs to design a rectangular web page with a given target area.

The dimensions of the rectangle, length LL and width WW, must satisfy the following conditions:

  • The area of the rectangle must equal the given area (LimesW=L imes W = area).

  • The length must be greater than or equal to the width (L≥WL \geq W).

  • The difference between the length LL and the width WW (L−WL - W) must be as small as possible.

Return an array [L, W] representing the optimal length and width of the rectangle.

Constraints:

  • 1≤1 \leq area ≤107\leq 10^7

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Construct the Rectangle

med
30 min
Try to solve the Construct the Rectangle problem.

Statement

A web developer needs to design a rectangular web page with a given target area.

The dimensions of the rectangle, length LL and width WW, must satisfy the following conditions:

  • The area of the rectangle must equal the given area (LimesW=L imes W = area).

  • The length must be greater than or equal to the width (L≥WL \geq W).

  • The difference between the length LL and the width WW (L−WL - W) must be as small as possible.

Return an array [L, W] representing the optimal length and width of the rectangle.

Constraints:

  • 1≤1 \leq area ≤107\leq 10^7