Bird
0
0
DSA Cprogramming~10 mins

Three Sum Problem All Unique Triplets 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 sort the array before processing.

DSA C
qsort(nums, numsSize, sizeof(int), [1]);
Drag options to blanks, or click blank then click option'
Acmpfunc
BcompareInts
CcompareFunc
Dcompare
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name for the comparator.
Not passing the comparator function pointer.
2fill in blank
medium

Complete the code to skip duplicate elements in the outer loop.

DSA C
for (int i = 0; i < numsSize - 2; i++) {
    if (i > 0 && nums[i] == nums[1]) continue;
Drag options to blanks, or click blank then click option'
Ai + 1
Bi - 1
Ci
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with the next element instead of previous.
Not checking i > 0 before accessing i-1.
3fill in blank
hard

Fix the error in the while loop condition to move the left pointer correctly.

DSA C
while (left < right && nums[left] == nums[1]) left++;
Drag options to blanks, or click blank then click option'
Aright
Bleft - 1
Cleft
Dleft + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with left - 1 which is behind the pointer.
Comparing with left itself causing infinite loop.
4fill in blank
hard

Fill both blanks to correctly move the right pointer and skip duplicates.

DSA C
while (left < right && nums[right] == nums[1]) [2];
Drag options to blanks, or click blank then click option'
Aright - 1
Bright + 1
Cright--
Dright++
Attempts:
3 left
💡 Hint
Common Mistakes
Using right + 1 which goes out of bounds.
Incrementing right pointer instead of decrementing.
5fill in blank
hard

Fill all three blanks to correctly add the triplet to the result array.

DSA C
result[*returnSize] = malloc(sizeof(int) * 3);
result[*returnSize][0] = nums[[1]];
result[*returnSize][1] = nums[[2]];
result[*returnSize][2] = nums[[3]];
(*returnSize)++;
Drag options to blanks, or click blank then click option'
Ai
Bleft
Cright
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices like k which is undefined here.
Mixing up left and right indices.