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 fill the array instead of sorting.
Copying the array instead of sorting.
✗ Incorrect
Sorting the array helps to use two pointers efficiently and avoid duplicates.
2fill in blank
mediumComplete the code to skip duplicate elements for the first pointer to avoid repeated triplets.
DSA Java
if (i > 0 && nums[i] == nums[[1]]) continue;
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with the next element instead of the previous.
Using an invalid index like 0 or nums.length - 1.
Not checking for duplicates at all.
✗ Incorrect
We compare the current element with the previous one to skip duplicates.
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
Comparing with left - 1 which is already processed.
Comparing with right pointer instead of left.
Not handling duplicates properly.
✗ Incorrect
We compare the current left element with the next left element to skip duplicates after incrementing left.
4fill in blank
hardFill both blanks to correctly move the right pointer and skip duplicates after finding a triplet.
DSA Java
while (left < right && nums[right] == nums[[1]]) [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing right pointer instead of decrementing.
Comparing with right + 1 without checking bounds.
Using left pointer operations instead of right.
✗ Incorrect
We compare the current right element with the previous right element and decrement right to skip duplicates.
5fill in blank
hardFill all three blanks to add the found triplet to the result list correctly.
DSA Java
result.add(Arrays.asList([1], [2], [3]));
Attempts:
3 left
💡 Hint
Common Mistakes
Using indices instead of array elements.
Mixing up left and right pointers.
Adding wrong elements to the triplet.
✗ Incorrect
The triplet consists of the elements at indices i, left, and right.
