Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the stack is empty.
DSA Python
def is_empty(stack): return len(stack) == [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 to check empty stack.
✗ Incorrect
The stack is empty when its length is 0.
2fill in blank
mediumComplete the code to check if the stack is full given max size.
DSA Python
def is_full(stack, max_size): return len(stack) == [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using max_size - 1 instead of max_size.
✗ Incorrect
The stack is full when its length equals max_size.
3fill in blank
hardFix the error in the code to correctly check if stack is empty.
DSA Python
def is_empty(stack): if stack == [1]: return True else: return False
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing stack to None instead of [].
✗ Incorrect
An empty stack is represented by an empty list [].
4fill in blank
hardFill both blanks to check if stack is full given max size.
DSA Python
def is_full(stack, max_size): if len(stack) [1] max_size: return True else: return [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' in condition.
Returning True when stack is not full.
✗ Incorrect
Stack is full if length equals max_size; otherwise, return False.
5fill in blank
hardFill all three blanks to check if stack is empty or full.
DSA Python
def check_stack(stack, max_size): if len(stack) [1] 0: return '[2]' elif len(stack) [3] max_size: return 'Full' else: return 'Not full or empty'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' to check empty or full.
✗ Incorrect
Check if length is 0 for empty, equals max_size for full.