Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push a number onto the stack.
DSA Typescript
stack.[1](num);Attempts:
3 left
💡 Hint
Common Mistakes
Using pop instead of push to add elements.
✗ Incorrect
To add an element to the top of the stack, we use the push method.
2fill in blank
mediumComplete the code to remove the top element from the stack.
DSA Typescript
const top = stack.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of pop to remove elements.
✗ Incorrect
The pop method removes and returns the last element from the stack.
3fill in blank
hardFix the error in the code to correctly check if a character is an operator.
DSA Typescript
if (['+', '-', '*', '/'].[1](char)) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using contains or has which are not valid array methods in TypeScript.
✗ Incorrect
The includes method checks if an array contains a specific element and returns true or false.
4fill in blank
hardFill both blanks to correctly perform the operation on two operands.
DSA Typescript
const result = operand1 [1] operand2; // [2] operator
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - when the comment says multiplication.
✗ Incorrect
The * operator multiplies operand1 and operand2.
5fill in blank
hardFill all three blanks to correctly evaluate the postfix expression step by step.
DSA Typescript
const operand2 = stack.[1](); const operand1 = stack.[2](); const result = operand1 [3] operand2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using push instead of pop to get operands.
Using - instead of + for addition.
✗ Incorrect
We pop operand2 and operand1 from the stack, then add them using +.
