Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the slow pointer at the start of the array.
DSA Java
int slow = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting slow pointer at 1 instead of 0.
Initializing slow pointer with array length.
✗ Incorrect
The slow pointer starts at index 0 to track the position of unique elements.
2fill in blank
mediumComplete the code to start the fast pointer from the second element.
DSA Java
for (int fast = [1]; fast < nums.length; fast++) {
Attempts:
3 left
💡 Hint
Common Mistakes
Starting fast pointer at 0 causing redundant comparison.
Starting fast pointer beyond the second element.
✗ Incorrect
The fast pointer starts at index 1 to compare with the slow pointer's element.
3fill in blank
hardFix the error in the condition to check if current fast element is different from slow element.
DSA Java
if (nums[fast] [1] nums[slow]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' causing no duplicates to be removed.
Using greater than or less than operators which are incorrect here.
✗ Incorrect
We check if the fast element is not equal to the slow element to find a new unique element.
4fill in blank
hardFill both blanks to update the slow pointer and assign the new unique element.
DSA Java
slow[1]; nums[slow] = nums[[2]];
Attempts:
3 left
💡 Hint
Common Mistakes
Decrementing slow pointer instead of incrementing.
Assigning nums[slow] to nums[slow] instead of nums[fast].
✗ Incorrect
We increment slow to move to the next position and assign nums[fast] to nums[slow].
5fill in blank
hardFill all three blanks to return the length of unique elements after processing.
DSA Java
return slow [1] [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Returning slow without adding 1 causing off-by-one error.
Subtracting 1 from slow causing negative or wrong length.
✗ Incorrect
We return slow + 1 because slow is index-based, so length is index + 1.
