LeetCode 956, Hard. Topics: Array, Dynamic Programming, Meet in the Middle, Knapsack Problem, 0-1 Knapsack. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 22 parametrized pytest cases, and a playground notebook:
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.
Examples
Explanation: We have two disjoint subsets {1,2,3} and {6}, which have the same sum = 6.
Explanation: We have two disjoint subsets {2,3,5} and {4,6}, which have the same sum = 10.
Explanation: The billboard cannot be supported, so we return 0.
Constraints
- 1 <= rods.length <= 20
- 1 <= rods[i] <= 1000
- sum(rods[i]) <= 5000
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026