← Back to challenges

The District Skylines

PythonHardalgorithmsarrayslogicloops

Instructions

The function is given a rectangular grid of buildings height. One can look from the left and from the top to the district and see vertical and horizontal skylines. Each shorter building can be increased in such a way such that the two skylines are not affected. Determine the total maximum increase in all buildings whenever possible.

Examples

max_increase([[0, 1], [1, 0]]) ➞ 2
# Vertical and Horizontal skylines are [1, 1].
# Thus each 0 can be increased by 1.

max_increase([[2, 1, 1], [1, 1, 0], [2, 0, 1]]) ➞ 2
# Vertical skyline is [2, 1, 2]
# Horizontal skyline is [2, 1, 1]

max_increase([[0, 1, 1], [0, 3, 1], [2, 2, 3]]) ➞ 6
# Vertical skyline is [1, 3, 3]
# Horizontal skyline is [2, 3, 3]

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.