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 C++
int slow = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting slow pointer at 1 instead of 0.
Using negative indices which are invalid here.
✗ Incorrect
The slow pointer starts at index 0 to track the position of unique elements.
2fill in blank
mediumComplete the code to iterate through the array starting from the second element.
DSA C++
for (int fast = [1]; fast < nums.size(); fast++) {
Attempts:
3 left
💡 Hint
Common Mistakes
Starting fast pointer at 0 causing redundant comparison.
Starting at index beyond array size.
✗ Incorrect
The fast pointer starts at index 1 to compare with the slow pointer at index 0.
3fill in blank
hardFix the error in the condition to check if current element is different from last unique element.
DSA C++
if (nums[fast] [1] nums[slow]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which detects duplicates instead of unique elements.
Using '<' or '>' which is not reliable for equality check.
✗ Incorrect
We check if the current element is not equal to the last unique element to identify duplicates.
4fill in blank
hardFill both blanks to update the slow pointer and assign the new unique element.
DSA C++
[1]; nums[slow] = nums[[2]];
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning nums[slow] to nums[fast] instead of the other way.
Not incrementing slow pointer before assignment.
✗ Incorrect
We first move slow pointer forward, then assign the current fast element to that position.
5fill in blank
hardFill all three blanks to complete the function returning the count of unique elements.
DSA C++
int removeDuplicates(vector<int>& nums) {
if (nums.empty()) return 0;
int slow = [1];
for (int fast = [2]; fast < nums.size(); fast++) {
if (nums[fast] != nums[slow]) {
slow[3];
nums[slow] = nums[fast];
}
}
return slow + 1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Starting slow or fast pointers at wrong indices.
Using decrement operator on slow pointer.
✗ Incorrect
Initialize slow at 0, fast at 1, and increment slow before assignment to track unique elements.
