FunctionRacerProblemsRace

Biggest Billboard Under the Skyline

HardStacks and queuesPython, JavaScript, TypeScript, Java, C++

A skyline is a row of buildings standing side by side with no gaps. Building i is widths[i] wide and heights[i] tall. A billboard is a rectangle that stands on the ground and covers a run of one or more neighbouring buildings in full: its width is the sum of their widths, and its height is the height of the shortest building in the run, because it must fit under all of them.

Return the largest possible area of a billboard. A building of height 0 can only be part of a billboard of area 0.

Example 1

widths [1,1,1,1,1,1]
heights [2,1,5,6,2,3]
returns 10

All buildings are 1 wide, so this is the classic skyline 2,1,5,6,2,3: the buildings of height 5 and 6 give a billboard 2 wide and 5 tall.

Example 2

widths [2,1,3]
heights [3,1,2]
returns 6

The first building alone gives 2 * 3 = 6, the last alone gives 3 * 2 = 6, and all three together give width 6 at height 1, also 6.

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 Stacks and queues problems