Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the input vector before processing.
DSA Rust
nums.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using reverse instead of sort.
Trying to shuffle the vector.
Removing elements instead of sorting.
✗ Incorrect
Sorting the vector helps to efficiently find triplets and avoid duplicates.
2fill in blank
mediumComplete the code to skip duplicate elements for the first pointer i.
DSA Rust
if i > 0 && nums[i] == nums[i[1]] { continue; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i + 1 which looks ahead instead of behind.
Using multiplication or division which is incorrect here.
✗ 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 right pointer correctly.
DSA Rust
while left < right && nums[right] [1] sum { right -= 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than.
Using equality which stops too early.
Using not equal which is incorrect here.
✗ Incorrect
We move the right pointer leftwards while the value is greater than the target sum.
4fill in blank
hardFill both blanks to skip duplicates for left and right pointers after finding a valid triplet.
DSA Rust
while left < right && nums[left] == nums[left[1]] { left += 1; } while left < right && nums[right] == nums[right[2]] { right -= 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong direction for increment or decrement.
Skipping too many elements by using +2 or -2.
✗ Incorrect
We move left forward and right backward to skip duplicates after adding a triplet.
5fill in blank
hardFill all three blanks to correctly add the found triplet to the result vector.
DSA Rust
result.push(vec![nums[[1]], nums[[2]], nums[[3]]]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum which is not an index.
Mixing up the order of pointers.
✗ Incorrect
The triplet consists of elements at indices i, left, and right.
