Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the second pointer for the two-pointer technique.
DSA Javascript
let i = 0; let [1] = 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same variable name for both pointers.
Choosing a pointer name that is not a single letter.
✗ Incorrect
The second pointer is commonly named 'j' to traverse the array while 'i' tracks the position of unique elements.
2fill in blank
mediumComplete the code to compare elements at the two pointers.
DSA Javascript
if (nums[[1]] !== nums[i]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing the element at 'i' with itself.
Using an undefined pointer variable.
✗ Incorrect
We compare the element at the second pointer 'j' with the element at 'i' to find duplicates.
3fill in blank
hardFix the error in updating the unique elements count.
DSA Javascript
i[1];Attempts:
3 left
💡 Hint
Common Mistakes
Decrementing the pointer instead of incrementing.
Increasing by 2 which skips positions.
✗ Incorrect
We increment 'i' by 1 to move to the next position for storing a unique element.
4fill in blank
hardFill both blanks to assign the new unique element and move the second pointer forward.
DSA Javascript
nums[i] = nums[[1]]; [2]++;
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing the wrong pointer.
Assigning from the wrong index.
✗ Incorrect
We assign the element at 'j' to position 'i' and then increment 'j' to continue scanning.
5fill in blank
hardFill all three blanks to complete the two-pointer loop for removing duplicates.
DSA Javascript
while ([1] < nums.length) { if (nums[[2]] !== nums[i]) { i++; nums[i] = nums[[3]]; } [1]++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'i' and 'j' in scanning positions.
Incrementing the wrong pointer in the loop.
✗ Incorrect
The pointer 'j' scans through the array, so all blanks related to scanning use 'j'.
