bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 492. Construct the Rectangle

492. Construct the Rectangle

Leetcode Solutions

Optimal Rectangle Construction

  1. Calculate the square root of the given area.
  2. Cast the square root to an integer to get the starting width value.
  3. Iterate from the starting width down to 1.
  4. For each width value, check if it divides the area evenly (no remainder).
  5. If it does, calculate the length by dividing the area by the width.
  6. Return the length and width as the dimensions of the rectangle.
UML Thumbnail

Brute Force Rectangle Construction

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...