Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same index variable 'i' for both arrays.
Using an undefined variable as index.
✗ Incorrect
We compare arr1[i] with arr2[j], so the index in arr2 should be 'j'.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing the wrong pointer.
Decrementing the pointer instead of incrementing.
✗ Incorrect
After swapping, we move the pointer 'j' forward by 1 to check the next element in arr2.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same index 'k' for both elements.
Using an index that goes out of range.
✗ Incorrect
To compare adjacent elements, we check arr2[k] and arr2[k+1].
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same index for both elements.
Using indices that cause out-of-range errors.
✗ Incorrect
We compare arr2[k] with arr2[k+1] to swap if needed.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not incrementing 'j' correctly.
Using wrong indices in the nested loop causing errors.
✗ Incorrect
After swapping, increment 'j' by 1. In the nested loops, compare arr2[l] and arr2[l+1] to sort arr2.