Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA Typescript
stack.[1](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' which removes an element instead of adding.
Using 'peek' which only views the top element.
✗ Incorrect
The push method adds an element to the top of the stack.
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' which adds instead of removes.
Using 'peek' which only views without removing.
✗ Incorrect
The pop method removes and returns the top element of the stack.
3fill in blank
hardFix the error in the code to check the top element without removing it.
DSA Typescript
const top = stack.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' which removes the element.
Using 'push' which adds an element.
✗ Incorrect
The peek method returns the top element without removing it.
4fill in blank
hardFill both blanks to create a stack and add an element.
DSA Typescript
const stack = new [1](); stack.[2](10);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Queue' which is a different data structure.
Using 'pop' to add an element instead of 'push'.
✗ Incorrect
We create a new Stack and use push to add an element.
5fill in blank
hardFill the two blanks to remove the top element and check the new top.
DSA Typescript
stack.[1](); const newTop = stack.[2](); console.log(newTop);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'push' to remove an element.
Using 'pop' twice without peeking.
✗ Incorrect
First, pop removes the top element. Then, peek checks the new top element. Finally, we print it.
