All problems
0054HardArrayStackMonotonic StackRange Minimum/Maximum Query

Largest Cut from a Slate Wall

Tracked in this browser only
Write code

Trains the technique from

LeetCode 84Largest Rectangle in Histogram

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A quarry face is stored as columns, where columns[i] is how many square slate tiles are stacked in the i-th column. Every column is one tile wide, columns touch with no gap, and all of them rest on the same floor. A column may hold no tiles at all.

A cutter can lift out one rectangular slab. The slab has to span a run of neighbouring columns and sit flush on the floor, so its height can never exceed the shortest column it spans, and its width is the number of columns in the run.

Report the tile count of the biggest slab the cutter can lift, that is the largest value of run width times the smallest column height inside the run. If no column holds a tile, the answer is 0.

Examples

Example 1

Input
columns = [3, 6, 5, 8, 4]
Output
16

Spanning the last four columns caps the height at 4 tiles, giving 4 by 4. Nothing else reaches 16: the single tallest column only yields 8, and taking all five columns caps the height at 3 for a total of 15.

Example 2

Input
columns = [5, 5]
Output
10

Both columns are the same height, so the slab covers the whole face without wasting any height.

Example 3

Input
columns = [0, 0]
Output
0

The face is bare, so every run has a shortest height of zero and no slab can be lifted.

Constraints

  • 1 <= columns.length <= 10^5
  • 0 <= columns[i] <= 10^4

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def largest_slate_cut(columns: list[int]) -> int:
Java
public int largestSlateCut(int[] columns)
September 7
Apply