Bird
0
0
DSA Cprogramming~10 mins

Merge Two Sorted Arrays Without Extra Space in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to swap two integers using pointers.

DSA C
void swap(int *a, int *b) {
    int temp = *a;
    *a = [1];
    *b = temp;
}
Drag options to blanks, or click blank then click option'
Aa
B*a
Ctemp
D*b
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of dereferencing pointers.
2fill in blank
medium

Complete the condition to check if the first array element is greater than the second array element.

DSA C
if (arr1[i] [1] arr2[j]) {
    // swap logic
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than.
3fill in blank
hard

Fix the error in the loop condition to iterate over the first array.

DSA C
for (int i = 0; i [1] n; i++) {
    // processing
}
Drag options to blanks, or click blank then click option'
A>
B<
C>=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using > or >= causes no iterations or errors.
4fill in blank
hard

Fill both blanks to complete the nested loops for merging arrays.

DSA C
for (int i = 0; i [1] n; i++) {
    for (int j = 0; j [2] m; j++) {
        if (arr1[i] > arr2[j]) {
            swap(&arr1[i], &arr2[j]);
        }
    }
}
Drag options to blanks, or click blank then click option'
A<
B>
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes index out of range errors.
5fill in blank
hard

Fill all three blanks to complete the function that merges two sorted arrays without extra space.

DSA C
void merge(int arr1[], int arr2[], int n, int m) {
    for (int i = 0; i [1] n; i++) {
        if (arr1[i] > arr2[0]) {
            [2](&arr1[i], &arr2[0]);
            int first = arr2[0];
            int k;
            for (k = 1; k [3] m && arr2[k] < first; k++) {
                arr2[k - 1] = arr2[k];
            }
            arr2[k - 1] = first;
        }
    }
}
Drag options to blanks, or click blank then click option'
A<
Bswap
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < in loops.
Forgetting to swap elements.