Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA Go
stack = [] stack.[1]('(')
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of append will remove an element instead of adding.
Using remove will try to delete a specific element, not add one.
✗ Incorrect
We use append to add an element to the top of the stack.
2fill in blank
mediumComplete the code to check if the stack is empty.
DSA Go
if len(stack) [1] 0: print("Stack is empty")
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' will not correctly check for empty stack.
Using '!=' will be true for non-empty stacks.
✗ Incorrect
We check if length equals zero to know if the stack is empty.
3fill in blank
hardFix the error in popping the top element from the stack.
DSA Go
top = stack.[1]()Attempts:
3 left
💡 Hint
Common Mistakes
Using append will add an element instead of removing.
Using remove requires a value, not index.
✗ Incorrect
pop() removes and returns the last element from the stack.
4fill in blank
hardFill both blanks to check matching parentheses and pop from stack.
DSA Go
if stack and stack[-1] [1] '(': stack.[2]()
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will check for non-matching which is wrong here.
Using append instead of pop will add elements instead of removing.
✗ Incorrect
We check if top of stack is '(' and then pop it.
5fill in blank
hardFill all three blanks to complete the balanced parentheses check loop.
DSA Go
for char in expression: if char [1] '(': stack.[2](char) elif char [3] ')': if not stack: return False
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' will cause wrong comparisons.
Using pop instead of append when adding '(' will cause errors.
✗ Incorrect
We check if char is '(' to append it, and if char is ')' to check stack.
