Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the input array before processing.
DSA Javascript
nums.[1]((a, b) => a - b);Attempts:
3 left
💡 Hint
Common Mistakes
Using reverse instead of sort
Trying to filter before sorting
✗ Incorrect
Sorting the array helps to efficiently find quadruplets and avoid duplicates.
2fill in blank
mediumComplete the code to skip duplicate values for the first pointer i.
DSA Javascript
if (i > 0 && nums[i] === nums[i - 1]) [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Using break which exits the loop
Using return which exits the function
✗ Incorrect
Using 'continue' skips the current iteration to avoid duplicate quadruplets starting with the same number.
3fill in blank
hardFix the error in the while loop condition to move the left pointer correctly.
DSA Javascript
while (left < right && nums[left] === nums[left [1] 1]) left++;
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - causing out of range
Using * or / which are invalid here
✗ Incorrect
To check the previous element for duplicates, subtract 1 from left index.
4fill in blank
hardFill both blanks to correctly move the right pointer and skip duplicates.
DSA Javascript
while (left < right && nums[right] === nums[right [1] 1]) right[2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + for comparison
Using ++ which moves pointer wrong way
✗ Incorrect
We compare nums[right] with nums[right + 1] to skip duplicates (the position just passed when moving leftward), and decrement right pointer with --.
5fill in blank
hardFill all three blanks to add the found quadruplet and move both pointers.
DSA Javascript
result.push([nums[i], nums[j], nums[left], nums[right]]); left[1]; right[2]; while (left < right && nums[left] === nums[left [3] 1]) left++;
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pointer movements
Not skipping duplicates correctly
✗ Incorrect
After adding quadruplet, move left pointer forward with ++, right pointer backward with --, then skip duplicates by comparing with previous element using subtraction.
