Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:36:36+00:00 2026-05-25T11:36:36+00:00

I recently participated in a competition where I was asked this question. Given an

  • 0

I recently participated in a competition where I was asked this question. Given an array with lengths what is the area of the biggest rectangle that can be made using ALL the lengths. The lengths can be added but not broken in between.

Example:
[ 4,2,4,4,6,8 ] given this array the best we can do is make a rectangle of sides 8 and 6 like this.

enter image description here

giving an area of 8 * 6 = 48.

I am a beginner and even after a long hard think about how to do it I am unable to get anywhere. I am not looking for a solution but any clue to nudge me in the right direction would be appreciated.

TIA

Edit: Somebody pointed out(comment deleted now) that its difficult to explain the solution with just hints and not posting some code. Kindly post code if necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:36:36+00:00Added an answer on May 25, 2026 at 11:36 am

    The problem is NP-Hard, thus the backtracking solution [or other exponential solution as suggested by @vhallac] will be your best shot, since there is not known [and if P!=NP, there is no existing] polynomial solution for this kind of problem.

    NP-Hardness proof:

    First, we know that a rectangle consists of 4 edges, that are equal in pairs [e1=e2,e3=e4].

    We will show that if there is a polynomial algorithm A to this problem, we can also solve the Partition Problem, by the following algorithm:

    input: a group of numbers S=a1,a2,...,an
    output: true if and only if the numbers can be partitioned
    algorithm:
    sum <- a1 + a2 + .. + an
    lengths <- a1, a2 , ... , an , (sum*5), (sum*5)
    activate A with lengths.
    if A answered there is any rectangle [solution is not 0], answer True
    else answer False
    

    Correctness:

    (1) if there is a partition to S, let it be S1,S2, there is also a rectangle with edges: (sum*5),(sum*5),S1,S2, and the algorithm will yield True.

    (2) if the algorithm yields True, there is a rectangle available in lengths, since a1 + a2 + … + an < sum*5, there are 2 edges with length sum*5, since the 2 other edges must be made using all remaining lengths [as the question specified], each other edge is actually of length (a1 + a2 + ... + an)/2, and thus there is a legal partition to the problem.

    Conclusion: There is a reduction PARTITION<=(p) this problem, and thus, this problem is NP-Hard

    EDIT:

    the backtracking solution is pretty simple, get all possible rectangles, and check each of them to see which is the best.

    backtracking solution: pseudo-code:

    getAllRectangles(S,e1,e2,e3,e4,sol):
      if S == {}:
         if legalRectangle(e1,e2,e3,e4):
              sol.add((e1,e2,e3,e4))
      else: //S is not empty
         elem <- S[0]
          getAllRectangles(S-elem,e1+elem,e2,e3,e4,sol)
          getAllRectangles(S-elem,e1,e2+elem,e3,e4,sol)
          getAllRectangles(S-elem,e1,e2,e3+elem,e4,sol)
          getAllRectangles(S-elem,e1,e2,e3,e4+elem,sol)
    
    getRectangle(S):
      RECS <- new Set
      getAllRectangles(S,{},{},{},{},RECS)
      getBest(RECS)
    

    EDIT2:

    As discussed in the comments, this answer shows not only this is hard to find the BEST rectangle, it is also hard to find ANY rectangle, making this problem hard for heuristic solutions as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I asked this question: Find Common Values in several arrays, or lists VB.NET
I recently participated a project that replaced a mainframe system with a web (asp.net
Recently I found about this tool easy_install that help me to easy install additional
Recently I asked a question on stackoverflow about multiline tabs. Below is the link
Recently I was confused by this question . Maybe because I didn't read language
Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
Recently I'm doing some work on RTMP streaming, that is using Flowplayer to integrate
Recently I've noticed that on occasion I do not get a mayorship notification when
Recently, we discovered odd behavior in some old code. This code has worked for
Recently I've read this performance guide Let's make the web faster and was puzzled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.