Tallest Billboard - Problem
You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.
You are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them together to make a support of length 6.
Return the largest possible height of your billboard installation. If you cannot support the billboard, return 0.
Input & Output
Example 1 — Basic Case
$
Input:
rods = [1,2,3,6]
›
Output:
6
💡 Note:
We can build supports of equal height 6: Left support uses rods [1,2,3] with total length 6, Right support uses rod [6] with length 6
Example 2 — No Solution
$
Input:
rods = [1,2,3,4]
›
Output:
0
💡 Note:
No way to split rods [1,2,3,4] into two equal-height supports. Total sum is 10, so we need each support to have height 5, but no subset sums to 5
Example 3 — Multiple Solutions
$
Input:
rods = [1,2]
›
Output:
0
💡 Note:
Only one rod per support would give heights 1 and 2 (not equal). Cannot make equal heights with these rods
Constraints
- 1 ≤ rods.length ≤ 20
- 1 ≤ rods[i] ≤ 1000
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code