Mark As Completed Discussion

Good morning! Here's our prompt for today.

We're given a histogram like the following, where contiguous (sharing a common border or touching) bars are made up of different heights. Let's assume all bars have the same width.

Description

The histogram is converted to an array of the heights of the bars:

JAVASCRIPT
1const histArr = [3, 1, 4, 2, 2, 1]

With this knowledge, can we find the largest rectangular area within the histogram? For the above, it would be the area outlined below:

Description

With the above histogram, calling maxRectInHist(histArr) would get us 6. Can you fill in the method?

Constraints

  • Length of the array <= 100000
  • The array can be empty
  • The array will contain values between 1 and 10000
  • The final answer will always fit in the integer range
  • Expected time complexity : O(n)
  • Expected space complexity : O(n)

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's how we would solve this problem...

How do I use this guide?

Access all course materials today

The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

Returning members can login to stop seeing this.