Back to photostream

Construct the Rectangle Leetcode Solution

The problem Construct the Rectangle Leetcode Solution states that you are a web designer. And you are given a task to design a web page with some pre-defined area. There are some constraints imposed upon the design. The length of the web page needs to be greater or equal to the width of the web page, the area of the designed web page must be equal to the given area. Last but not the least, the difference between the length and width should be as small as possible. So, let's take a look at a few examples before diving deep into solving the problem.

 

area = 4

 

Explanation: The length and width of the web page with an area equal to 4 can be either 1x4 or 2x2. But since we need to find the length and width such that they have a minimum difference between them. It's better to choose 2x2 dimensions. The 2x2 dimension also follows that the length is greater or equal to the width of the page.

area = 23

 

Explanation: You can have only two web pages with area = 23. you can either have dimensions 23x1 or 1x23. Since the web-page with dimensions 1x23 violates our first condition. We can have the web-page with size 23x1 only.

Approach for Construct the Rectangle Leetcode Solution

The problem Construct the Rectangle Leetcode Solution asks us to find out the suitable size of the web-page with some pre-defined area. The web-page dimensions should satisfy the imposed constraints.

 

www.tutorialcup.com/leetcode-solutions/construct-the-rect...

16 views
0 faves
0 comments
Uploaded on September 13, 2021