Imagine you're constructing a massive billboard that needs to be perfectly balanced with two steel supports of equal height on each side. You have a collection of steel rods with various lengths that can be welded together to create these supports.
Your goal is to maximize the height of your billboard by cleverly selecting and grouping rods to form two supports of identical height. Each rod can be used in at most one support, or not used at all.
For example, with rods of lengths [1, 2, 3, 6], you could create two supports of height 6: one using the single rod of length 6, and another by welding together rods of lengths 1, 2, and 3.
Return the maximum possible height of equal supports. If it's impossible to create two equal-height supports, return 0.
Input & Output
Visualization
Time & Space Complexity
For each of n rods, we have 3 choices (left, right, unused), leading to 3^n combinations
Recursion depth is at most n levels deep
Constraints
- 1 โค rods.length โค 20
- 1 โค rods[i] โค 1000
- Sum of all rod lengths โค 5000
- Each rod can be used in at most one support or not used at all