FastPrepLargest Rectangle in Histogram
Problems/Largest Rectangle in Histogram

Largest Rectangle in Histogram

Kotak Mahindra Bank logoKotak Mahindra Bank● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source report identifies the linked Largest Rectangle in Histogram task. The callable signature, examples, and execution bounds reuse the equivalent reviewed FastPrep task; estimated source fidelity is 95%.

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

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

The best area is 4, achieved either by the second bar alone or by both bars at height 2.

Example 3

heights = [0]return = 0

The only bar has height 0, so no positive-area rectangle exists.

Constraints

  • 1 <= heights.length <= 100000.
  • 0 <= heights[i] <= 10000.

More Kotak Mahindra Bank problems

  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Nov 2026
  • Maximum Non-Adjacent Coins in Two RowsONSITE INTERVIEW · Seen Oct 2026
All Kotak Mahindra Bank interview questionsSee Kotak Mahindra Bank hiring insights
Saved
class Solution {
    public int largestRectangleArea(int[] heights) {
        // Write your code here.
    }
}
Checking account…