FastPrepLargest Rectangle in Histogram
Problems/Largest Rectangle in Histogram

Largest Rectangle in Histogram

Shipsy logoShipsy● HardONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamples

Problem statement

Source note: This problem is backed by a real Shipsy technical interview report. The report directly named Largest Rectangle in Histogram and described both brute force and the optimal monotonic-stack direction, but it did not include a function interface, examples, or constraints. The core task match is about 95%.

Given an array heights of non-negative bar heights, where every bar has width 1, return the area of the largest rectangle that can be formed using one or more consecutive bars.

Interview follow-up

The interviewer asked for a brute-force approach, why it is inefficient, the optimal monotonic-stack solution, time and space analysis, and a clean implementation. They emphasized understanding the reasoning rather than only reaching the final answer.

Function

largestRectangleArea(heights: int[]) → int

Examples

Example 1

heights = [2,1,5,6,2,3]return = 10

The bars of heights 5 and 6 form a rectangle of height 5 and width 2.

Example 2

heights = [2,4]return = 4

Similar questions at other companies

  • Trapping Rain WaterTeradata · ONSITE INTERVIEW
  • Trapping Rain WaterBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Visible People to the LeftGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Construct a Tree from Level-Order and Inorder TraversalsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Largest Rectangle in HistogramTekion · ONSITE INTERVIEWTekion interview questions
  • Trapping Rain WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Trapping Rain WaterKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Confirmed Profiling Events with First-Observed StartsAnthropic · PHONE SCREEN · ONSITE INTERVIEWAnthropic interview questions
  • Trapping Rain WaterNuro · ONSITE INTERVIEWNuro interview questions
  • Trapping Rain WaterMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
See Shipsy hiring insights
Saved
class Solution {
    public int largestRectangleArea(int[] heights) {
      // write your code here
    }
}
Checking account…