All practice tasks

Coding (Algo)

Find the Largest Solid Rectangle

Monotonic stack · Hard

A storage visualization represents adjacent unit-width columns with different non-negative heights. A solid rectangle must fit below every column it spans. The report needs the largest area, not the number of columns or the height of the tallest one.

Return the maximum area of a rectangle spanning consecutive unit-width bars without exceeding any selected height.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ heights: integer[] }

Fields

  • heights is the ordered array of non-negative integer bar heights. All bar widths are one.

Output

Return value

  • Return a numeric area. An empty histogram or all-zero heights returns zero.
  • The rectangle may span one or more consecutive bars. Its height is at most the shortest included bar.

Constraints

  • 0 <= heights.length <= 100000; 0 <= heights[i] <= 1000000000. Areas fit a safe JSON integer.

Examples

Example 1

{
  "heights": [
    2,
    1,
    5,
    6,
    2,
    3
  ]
}

Returns

10

Example 2

{
  "heights": [
    4,
    4,
    4
  ]
}

Returns

12

Required complexity

O(n) time and O(n) auxiliary space

What this task practices

Find the Largest Solid Rectangle is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.