Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the input array before processing.
DSA Java
Arrays.[1](nums);Attempts:
3 left
💡 Hint
Common Mistakes
Using reverse instead of sort.
Trying to sort manually instead of using built-in method.
✗ Incorrect
Sorting the array helps to use two pointers efficiently and avoid duplicates.
2fill in blank
mediumComplete the code to skip duplicate values for the first pointer i.
DSA Java
if (i > 0 && nums[i] == nums[[1]]) continue;
Attempts:
3 left
💡 Hint
Common Mistakes
Using i + 1 which looks ahead instead of behind.
Comparing with 0 index always.
✗ Incorrect
To avoid duplicates, skip when current element equals previous element at i-1.
3fill in blank
hardFix the error in the while loop condition to move the left pointer correctly.
DSA Java
while (left < right && nums[left] == nums[[1]]) left++;
Attempts:
3 left
💡 Hint
Common Mistakes
Using left + 1 which is the next element, causing index errors.
Comparing with right pointer instead of left.
✗ Incorrect
We compare current left element with the previous left element at left-1 to skip duplicates.
4fill in blank
hardFill both blanks to correctly move the right pointer and skip duplicates.
DSA Java
while (left < right && nums[right] == nums[[1]]) [2]--;
Attempts:
3 left
💡 Hint
Common Mistakes
Using right + 1 instead of right - 1.
Comparing with left pointer instead of right.
✗ Incorrect
To skip duplicates on the right side, compare with previous right element at right-1 and decrement right.
5fill in blank
hardFill all three blanks to add the quadruplet to the result list correctly.
DSA Java
result.add(Arrays.asList(nums[[1]], nums[[2]], nums[[3]], nums[right]));
Attempts:
3 left
💡 Hint
Common Mistakes
Using right twice or missing left pointer.
Mixing indices order.
✗ Incorrect
The quadruplet consists of elements at indices i, j, left, and right.
