BBarCumulus
Workflows

Coding workflows · Maximum histogram rectangle

03
Built around your work

A concrete starting point

Find the largest rectangle beneath unit-width histogram bars with at most 256 integer heights from zero through 1000000. Check empty input and equal heights, rejecting negative or Boolean values without changing the input.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Maximum histogram rectangle

A concrete starting point
def histogram_area(heights):
    heights = tuple(heights)
    if len(heights) > 256 or any(type(h) is not int or not 0 <= h <= 1000000 for h in heights):
        raise ValueError("height.range")
    stack, best = [], 0
    for i in range(len(heights) + 1):
        current = heights[i] if i < len(heights) else 0
        while stack and heights[stack[-1]] > current:
            height = heights[stack.pop()]
            start = stack[-1] + 1 if stack else 0
            best = max(best, height * (i - start))
        stack.append(i)
    return best

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗