Challenge - 5 Problems
Array Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput after deleting middle element from an array
What is the output of the following Go code that deletes the middle element from an array?
DSA Go
package main import "fmt" func main() { arr := []int{10, 20, 30, 40, 50} mid := len(arr) / 2 arr = append(arr[:mid], arr[mid+1:]...) fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Remember that deleting the middle element means removing the element at index len(arr)/2.
✗ Incorrect
The middle index is 2 (0-based), so element 30 is removed. The resulting array is [10 20 40 50].
❓ Predict Output
intermediateResult of deleting middle element from even-length array
What is the output of this Go code deleting the middle element from an even-length array?
DSA Go
package main import "fmt" func main() { arr := []int{5, 10, 15, 20, 25, 30} mid := len(arr) / 2 arr = append(arr[:mid], arr[mid+1:]...) fmt.Println(arr) }
Attempts:
2 left
💡 Hint
For even length, middle index is len(arr)/2 which is 3 here.
✗ Incorrect
The middle index is 3, so element 20 is removed. The resulting array is [5 10 15 25 30].
🔧 Debug
advancedIdentify the error in array deletion code
What error does this Go code produce when trying to delete the middle element?
DSA Go
package main import "fmt" func main() { arr := []int{1, 2, 3, 4, 5} mid := len(arr) / 2 arr = append(arr[:mid], arr[mid:]...) fmt.Println(arr) }
Attempts:
2 left
💡 Hint
Check the slice indices used in append carefully.
✗ Incorrect
The code appends arr[mid:] instead of arr[mid+1:], so the middle element is not removed. The output is the original array [1 2 3 4 5].
🧠 Conceptual
advancedEffect of deleting middle element on array length
If you delete the middle element from an array of length n, what will be the length of the resulting array?
Attempts:
2 left
💡 Hint
Deleting one element reduces the length by one.
✗ Incorrect
Removing one element from an array reduces its length by exactly one.
🚀 Application
expertFinal array after multiple middle deletions
Starting with array [2, 4, 6, 8, 10, 12, 14], delete the middle element three times in a row. What is the final array?
Attempts:
2 left
💡 Hint
After each deletion, recalculate the middle index for the new array.
✗ Incorrect
Deletions remove elements at indices 3 (8), then 3 (10), then 2 (6), resulting in [2 4 12 14].
