Challenge - 5 Problems
Array Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output after deleting middle element from an odd-length array
What is the output of the following code after deleting the middle element from the array?
DSA Python
arr = [10, 20, 30, 40, 50] mid = len(arr) // 2 arr.pop(mid) print(arr)
Attempts:
2 left
💡 Hint
Remember that integer division // gives the middle index for odd-length arrays.
✗ Incorrect
The middle index for the array of length 5 is 2 (0-based). Removing element at index 2 removes 30, so the array becomes [10, 20, 40, 50].
❓ Predict Output
intermediate2:00remaining
Output after deleting middle element from an even-length array
What is the output of the following code after deleting the middle element from the array?
DSA Python
arr = [5, 15, 25, 35, 45, 55] mid = len(arr) // 2 arr.pop(mid) print(arr)
Attempts:
2 left
💡 Hint
For even length, integer division picks the higher middle index.
✗ Incorrect
The length is 6, so mid = 3. Removing element at index 3 removes 35, so the array becomes [5, 15, 25, 45, 55].
🔧 Debug
advanced2:00remaining
Identify the error in deleting middle element
What error will this code produce when trying to delete the middle element?
DSA Python
arr = [1, 2, 3, 4] mid = len(arr) / 2 arr.pop(mid) print(arr)
Attempts:
2 left
💡 Hint
Check the type of mid and what pop expects as index.
✗ Incorrect
len(arr) / 2 returns a float (2.0). pop() requires an integer index, so passing a float causes a TypeError.
🧠 Conceptual
advanced1:00remaining
Effect of deleting middle element on array length
If an array has 7 elements, what will be its length after deleting the middle element?
Attempts:
2 left
💡 Hint
Deleting one element reduces length by one.
✗ Incorrect
Deleting one element from 7 elements leaves 6 elements.
❓ Predict Output
expert3:00remaining
Output after deleting middle element in a loop
What is the final output of the code after deleting the middle element repeatedly until the array is empty?
DSA Python
arr = [1, 2, 3, 4, 5] while arr: mid = len(arr) // 2 arr.pop(mid) print(arr)
Attempts:
2 left
💡 Hint
Each loop removes the middle element until no elements remain.
✗ Incorrect
The loop removes the middle element repeatedly until the array is empty, so the final output is an empty list [].