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 comparator function name.
Passing NULL instead of a comparator.
✗ Incorrect
The qsort function requires a comparison function pointer. 'compareInts' is the correct comparator for integers.
2fill in blank
mediumComplete the code to skip duplicate elements in the first loop.
DSA C
for (int i = 0; i < numsSize - 3; 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 i+1 which is the next element.
Comparing with i itself causing no skip.
✗ 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 avoid infinite loops.
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 may cause out-of-bound errors.
Comparing with left-1 which is invalid when left is 0.
✗ Incorrect
We compare nums[left] with nums[right] to skip duplicates after finding a quadruplet.
4fill in blank
hardFill both blanks to correctly update pointers after finding a quadruplet.
DSA C
quadruplets[quadrupletCount][0] = nums[i]; quadruplets[quadrupletCount][1] = nums[j]; quadruplets[quadrupletCount][2] = nums[left]; quadruplets[quadrupletCount][3] = nums[right]; quadrupletCount++; while (left < right && nums[left] == nums[left [1]]) left++; while (left < right && nums[right] == nums[right [2]]) right--;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 for left pointer which moves it backward incorrectly.
Using +1 for right pointer which moves it forward incorrectly.
✗ Incorrect
After adding a quadruplet, move left pointer forward by 1 and right pointer backward by 1 to skip duplicates.
5fill in blank
hardFill all three blanks to complete the condition checking if the sum matches the target.
DSA C
int sum = nums[i] + nums[j] + nums[left] + nums[right]; if (sum [1] target) { left++; } else if (sum [2] target) { right--; } else if (sum == target) { // add quadruplet [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison operators.
Not moving pointers correctly based on sum comparison.
✗ Incorrect
If sum is less than target, move left pointer forward; if greater, move right pointer backward; if equal, add quadruplet.
