1261. Tallest Billboard

HardDynamic Programming0/1 Knapsack

Given rods of various lengths, build two supports of equal height by welding subsets of rods together (each rod used at most once, and rods may be left unused). Return the largest possible common height, or 0 if no two disjoint subsets have equal sums. The input is JSON {rods}.

Input: JSON {rods}.

Output: Integer — the tallest achievable equal height.

Examples

Example 1
Input: {"rods":[1,2,3,6]}
Output: 6
Explanation: 1+2+3 equals 6.
Example 2
Input: {"rods":[1,2,3,4,5,6]}
Output: 10
Explanation: Two disjoint subsets sum to 10.
Example 3
Input: {"rods":[1,2]}
Output: 0
Explanation: No equal split exists.

Constraints

Asked by

MicrosoftGoogleAmazon
Solve this problem in the editor →