Challenge - 5 Problems
Array Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output after deleting the last element?
Consider the following TypeScript code that deletes the last element from an array. What will be the printed output?
DSA Typescript
const arr = [10, 20, 30, 40, 50]; arr.pop(); console.log(arr);
Attempts:
2 left
💡 Hint
The pop() method removes the last element from the array.
✗ Incorrect
The pop() method removes the last element (50) from the array, so the remaining elements are [10, 20, 30, 40].
❓ Predict Output
intermediateWhat happens if pop() is called on an empty array?
What will be the output of the following TypeScript code?
DSA Typescript
const arr: number[] = []; const removed = arr.pop(); console.log(removed); console.log(arr);
Attempts:
2 left
💡 Hint
pop() returns undefined if the array is empty.
✗ Incorrect
Calling pop() on an empty array returns undefined and the array remains empty.
🔧 Debug
advancedWhy does this code throw an error when deleting the last element?
Identify the error in the following TypeScript code that tries to delete the last element from an array.
DSA Typescript
const arr = [1, 2, 3]; arr.pop; console.log(arr);
Attempts:
2 left
💡 Hint
Check if pop is called with parentheses.
✗ Incorrect
pop is a function and must be called with parentheses (). Without them, the method is not executed and the array remains unchanged.
❓ Predict Output
advancedWhat is the array after multiple deletions at the end?
What will be the output after executing the following code?
DSA Typescript
const arr = [5, 10, 15, 20, 25]; arr.pop(); arr.pop(); console.log(arr);
Attempts:
2 left
💡 Hint
Each pop removes one element from the end.
✗ Incorrect
Two pop() calls remove 25 and then 20, leaving [5, 10, 15].
🧠 Conceptual
expertWhat is the time complexity of deleting the last element from an array?
In most programming languages including TypeScript, what is the time complexity of deleting the last element from a dynamic array using pop()?
Attempts:
2 left
💡 Hint
Consider how pop() works internally on dynamic arrays.
✗ Incorrect
Deleting the last element with pop() is a constant time operation because it just removes the last item without shifting others.
