Two Towers of One Height
You have blocks with the heights listed in blocks. Build two towers of exactly the same height by stacking blocks; each block goes into one tower at most, and blocks may be left over.
Return the largest height both towers can have, or 0 if two equal towers cannot be built.
Example 1
blocks [3,4,7,2]
returns 7
3 + 4 and 7 make two towers of height 7. The 2 is left over.
Example 2
blocks [1,2]
returns 0
The two blocks differ, and a tower of no blocks does not count as a tower of height 1 or 2.
Constraints
1 <= len(blocks) <= 201 <= blocks[i] <= 250
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Dynamic programming problems
- Factorials Up to nBeginner
- Fibonacci NumberBeginner
- Frog Across the StonesBeginner
- Hop One or ThreeBeginner
- N-th Tribonacci NumberBeginner
- Paving With Colored SlabsBeginner
- Pell NumbersBeginner
- Savings With InterestBeginner