0
0
DSA Pythonprogramming~20 mins

Array Deletion at Middle Index in DSA Python - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[10, 30, 40, 50]
B[10, 20, 30, 40]
C[20, 30, 40, 50]
D[10, 20, 40, 50]
Attempts:
2 left
💡 Hint
Remember that integer division // gives the middle index for odd-length arrays.
Predict Output
intermediate
2: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)
A[5, 15, 25, 45, 55]
B[15, 25, 35, 45, 55]
C[5, 15, 25, 35, 45]
D[5, 15, 35, 45, 55]
Attempts:
2 left
💡 Hint
For even length, integer division picks the higher middle index.
🔧 Debug
advanced
2: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)
AIndexError: pop index out of range
BSyntaxError: invalid syntax
CTypeError: 'float' object cannot be interpreted as an integer
DNo error, output: [1, 2, 4]
Attempts:
2 left
💡 Hint
Check the type of mid and what pop expects as index.
🧠 Conceptual
advanced
1: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?
A7
B6
C5
D8
Attempts:
2 left
💡 Hint
Deleting one element reduces length by one.
Predict Output
expert
3: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)
A[]
B[3]
C[2]
D[1]
Attempts:
2 left
💡 Hint
Each loop removes the middle element until no elements remain.