0
0
DSA Pythonprogramming~10 mins

Largest Rectangle in Histogram Using Stack in DSA Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the stack as an empty list.

DSA Python
stack = [1]
Drag options to blanks, or click blank then click option'
A[]
B{}
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} which creates a set or dictionary.
Using None which is not a list.
Using 0 which is an integer, not a list.
2fill in blank
medium

Complete the code to append the current index i to the stack.

DSA Python
stack.[1](i)
Drag options to blanks, or click blank then click option'
Ainsert
Bremove
Cpop
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop which removes an element instead of adding.
Using insert which requires an index and is not typical for stack push.
Using remove which deletes a specific value.
3fill in blank
hard

Fix the error in the condition to check if the stack is not empty.

DSA Python
while stack and heights[i] < heights[[1]]:
Drag options to blanks, or click blank then click option'
Ai
Bstack[-1]
Cstack[0]
D-i
Attempts:
3 left
💡 Hint
Common Mistakes
Using stack[0] which is the bottom of the stack.
Using i which is the current index, not the top of the stack.
Using -i which is invalid indexing.
4fill in blank
hard

Fill both blanks to calculate the width correctly when popping from the stack.

DSA Python
width = i - [1] - [2]
Drag options to blanks, or click blank then click option'
Astack.pop()
Bstack[-1]
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using stack.pop() inside width calculation which removes an element again.
Using 0 instead of 1 which gives wrong width.
Using stack[0] which is bottom of stack, not top.
5fill in blank
hard

Fill both blanks to update max_area correctly inside the loop.

DSA Python
max_area = max(max_area, heights[[1]] * [2])
Drag options to blanks, or click blank then click option'
Astack.pop()
Bwidth
Cstack[-1]
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using stack[-1] instead of popping for height.
Using i instead of width for multiplication.
Not updating max_area with max function.