Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

90. Largest Rectangle in Histogram

HardDay 26 of 60Stack & Queue

You are given an array heights describing a histogram: bar i has width 1 and height heights[i], and the bars stand side by side. Return the area of the largest rectangle that fits entirely inside the histogram.

Example 1
Input: heights = [2,1,5,6,2,3]
Output: 10
The bars of height 5 and 6 together allow a rectangle of height 5 and width 2.
Example 2
Input: heights = [2,4]
Output: 4
Constraints
  • 1 <= heights.length <= 10^5
  • 0 <= heights[i] <= 10^4
Hints
Frequently asked at: Amazon, Google, Microsoft, Flipkart
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min