Bird
0
0
DSA Cprogramming~10 mins

Sort Colors Two Pointer Dutch Flag 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 initialize the left pointer to the start of the array.

DSA C
int left = [1];
Drag options to blanks, or click blank then click option'
A1
B0
C-1
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 or negative index.
2fill in blank
medium

Complete the code to initialize the right pointer to the end of the array.

DSA C
int right = [1] - 1;
Drag options to blanks, or click blank then click option'
An
Blength
Csize
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or length without subtracting 1.
3fill in blank
hard

Fix the error in the while loop condition to process elements correctly.

DSA C
while ([1]) {
Drag options to blanks, or click blank then click option'
Ai < right
Bleft <= right
Ci < left
Di <= right
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of <= causing last element to be skipped.
4fill in blank
hard

Fill both blanks to swap elements and update pointers correctly when nums[i] is 0.

DSA C
if (nums[i] == 0) {
    swap(nums, i, [1]);
    i++;
    [2]++;
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Ci
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with right pointer or incrementing wrong variables.
5fill in blank
hard

Fill all three blanks to swap elements and update pointers correctly when nums[i] is 2.

DSA C
else if (nums[i] == 2) {
    swap(nums, i, [1]);
    [2]--;
    [3] = [3];
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Ci
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing i after swapping with right pointer.