FunctionRacerProblemsRace

Two Towers of One Height

HardDynamic programmingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems