Bird
0
0
DSA Cprogramming~10 mins

Four Sum Problem All Unique Quadruplets 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'
AcompareInts
Bcmp
CcompareFunc
Dcompare
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong comparator function name.
Passing NULL instead of a comparator.
2fill in blank
medium

Complete 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'
Ai + 1
Bi
Ci - 1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with i+1 which is the next element.
Comparing with i itself causing no skip.
3fill in blank
hard

Fix 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'
Aright
Bleft + 1
Cleft - 1
Dright - 1
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.
4fill in blank
hard

Fill 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'
A+1
B-1
C+2
D-2
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.
5fill in blank
hard

Fill 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'
A<
B>
Csum = target
D/* add quadruplet code here */
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison operators.
Not moving pointers correctly based on sum comparison.