Skip to content

Commit 9c9f965

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 9ae64bc commit 9c9f965

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

data_structures/stacks/largest_rectangle_histogram.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
77
THESE ARE THE ALGORITHM'S RULES:
88
RULE 1: Scan `heights` array in left to right direction
9-
if the height at this index is greater than the height at the top position of `stack`
9+
if the height at this index is greater than the height at the top position of `stack`
1010
we push the index at `stack`.
1111
1212
RULE 2: If the `height` at the current `index` is smaller than the `height` at the top of the `stack`
13-
process the stack now. Pop top `index` from `stack`.
14-
The `height` of the rectangle = `height` at popped `index`.
15-
Calculate `width` of the rectangle:
16-
if the `stack` is not empty.
13+
process the stack now. Pop top `index` from `stack`.
14+
The `height` of the rectangle = `height` at popped `index`.
15+
Calculate `width` of the rectangle:
16+
if the `stack` is not empty.
1717
Then the `width` extends from `begin` of the `histogram` till current `index`.
1818
If the stack is not empty, the width stretches from a current index to an index that immediately comes after new stack top
1919
@@ -31,6 +31,7 @@
3131

3232
__author__ = "Ansh Dulewale"
3333

34+
3435
def largestRectangleArea(heights):
3536
stack = []
3637
max_area = 0
@@ -46,6 +47,7 @@ def largestRectangleArea(heights):
4647
heights.pop() # Restore the original heights array.
4748
return max_area
4849

50+
4951
# Get input from the user
5052
user_input = input()
5153
heights = list(map(int, user_input.split()))

0 commit comments

Comments
 (0)