0
0
DSA Pythonprogramming~10 mins

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

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

Complete the code to swap elements between two arrays.

DSA Python
if arr1[i] > arr2[[1]]:
    arr1[i], arr2[[1]] = arr2[[1]], arr1[i]
Drag options to blanks, or click blank then click option'
Ai
Bj
Ck
Dm
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same index variable 'i' for both arrays.
Using an undefined variable as index.
2fill in blank
medium

Complete the code to move the pointer in the second array.

DSA Python
while i < n and j < m:
    if arr1[i] > arr2[j]:
        arr1[i], arr2[j] = arr2[j], arr1[i]
        j = [1]
    else:
        i += 1
Drag options to blanks, or click blank then click option'
Ai - 1
Bi + 1
Cj - 1
Dj + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing the wrong pointer.
Decrementing the pointer instead of incrementing.
3fill in blank
hard

Fix the error in the code to correctly sort the second array after swapping.

DSA Python
for k in range(m-1):
    if arr2[k] > arr2[[1]]:
        arr2[k], arr2[[1]] = arr2[[1]], arr2[k]
Drag options to blanks, or click blank then click option'
Ak + 1
Bk - 1
Ck
Dm - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same index 'k' for both elements.
Using an index that goes out of range.
4fill in blank
hard

Fill both blanks to complete the inner loop that sorts arr2 after swapping.

DSA Python
for k in range(m-1):
    if arr2[[1]] > arr2[[2]]:
        arr2[[1]], arr2[[2]] = arr2[[2]], arr2[[1]]
Drag options to blanks, or click blank then click option'
Ak
Bk + 1
Cm - 1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same index for both elements.
Using indices that cause out-of-range errors.
5fill in blank
hard

Fill all three blanks to complete the merge function without extra space.

DSA Python
def merge(arr1, arr2, n, m):
    i, j = 0, 0
    while i < n and j < m:
        if arr1[i] > arr2[j]:
            arr1[i], arr2[j] = arr2[j], arr1[i]
            j = [1]
        else:
            i += 1
    for k in range(m-1):
        for l in range(m-1-k):
            if arr2[[2]] > arr2[[3]]:
                arr2[[2]], arr2[[3]] = arr2[[3]], arr2[[2]]
Drag options to blanks, or click blank then click option'
Aj + 1
Bl
Cl + 1
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Not incrementing 'j' correctly.
Using wrong indices in the nested loop causing errors.