Bird
0
0
DSA Cprogramming~20 mins

Array Deletion at Middle Index in DSA C - 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 array
What is the output of the following C code after deleting the middle element from the array?
DSA C
#include <stdio.h>

void deleteMiddle(int arr[], int *n) {
    int mid = *n / 2;
    for (int i = mid; i < *n - 1; i++) {
        arr[i] = arr[i + 1];
    }
    (*n)--;
}

int main() {
    int arr[] = {10, 20, 30, 40, 50};
    int n = 5;
    deleteMiddle(arr, &n);
    for (int i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
A10 20 30 50
B10 20 40 50
C20 30 40 50
D10 20 30 40 50
Attempts:
2 left
💡 Hint
Remember that deleting the middle element means shifting elements after the middle one to the left.
Predict Output
intermediate
2:00remaining
Resulting array size after middle deletion
What is the size of the array after deleting the middle element using the code below?
DSA C
void deleteMiddle(int arr[], int *n) {
    int mid = *n / 2;
    for (int i = mid; i < *n - 1; i++) {
        arr[i] = arr[i + 1];
    }
    (*n)--;
}

int main() {
    int arr[] = {1, 2, 3, 4, 5, 6};
    int n = 6;
    deleteMiddle(arr, &n);
    printf("%d", n);
    return 0;
}
A3
B6
C5
D4
Attempts:
2 left
💡 Hint
Deleting one element reduces the size by one.
🔧 Debug
advanced
2:00remaining
Identify the error in middle deletion code
What error will occur when running this code to delete the middle element?
DSA C
void deleteMiddle(int arr[], int *n) {
    int mid = (*n + 1) / 2;
    for (int i = mid; i < *n; i++) {
        arr[i] = arr[i + 1];
    }
    (*n)--;
}

int main() {
    int arr[] = {5, 10, 15, 20, 25};
    int n = 5;
    deleteMiddle(arr, &n);
    for (int i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
ARuntime error due to out-of-bounds access
BRuns correctly and outputs: 5 10 20 25
CRuns but outputs: 5 10 15 20 25
DCompilation error due to syntax
Attempts:
2 left
💡 Hint
Check the loop boundary and array indexing carefully.
Predict Output
advanced
2:00remaining
Output after deleting middle element from even-sized array
What is the output of this code after deleting the middle element from an even-sized array?
DSA C
#include <stdio.h>

void deleteMiddle(int arr[], int *n) {
    int mid = (*n - 1) / 2;
    for (int i = mid; i < *n - 1; i++) {
        arr[i] = arr[i + 1];
    }
    (*n)--;
}

int main() {
    int arr[] = {2, 4, 6, 8, 10, 12};
    int n = 6;
    deleteMiddle(arr, &n);
    for (int i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
    return 0;
}
A2 4 8 10 12
B2 4 6 8 10 12
C2 4 6 10 12
D4 6 8 10 12
Attempts:
2 left
💡 Hint
For even length, middle is the lower middle index.
🧠 Conceptual
expert
2:00remaining
Time complexity of deleting middle element in array
What is the time complexity of deleting the middle element from an array of size n by shifting elements?
AO(n^2) - Quadratic time
BO(log n) - Logarithmic time
CO(1) - Constant time
DO(n) - Linear time
Attempts:
2 left
💡 Hint
Consider how many elements need to be moved after deletion.