Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong function name for the comparator.
Not passing the comparator function pointer.
✗ Incorrect
The qsort function requires a comparison function pointer. 'cmpfunc' is the standard name used here.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with the next element instead of previous.
Not checking i > 0 before accessing i-1.
✗ Incorrect
To skip duplicates, compare current element with the previous one at index i-1.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with left - 1 which is behind the pointer.
Comparing with left itself causing infinite loop.
✗ Incorrect
To skip duplicates, compare nums[left] with nums[left + 1] and then move left forward.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using right + 1 which goes out of bounds.
Incrementing right pointer instead of decrementing.
✗ Incorrect
Compare nums[right] with nums[right - 1] and decrement right pointer to skip duplicates.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices like k which is undefined here.
Mixing up left and right indices.
✗ Incorrect
The triplet consists of nums[i], nums[left], and nums[right].
