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 which doesn't help.
Using pop which removes elements.
✗ Incorrect
Sorting the vector helps to efficiently find quadruplets and avoid duplicates.
2fill in blank
mediumComplete the code to skip duplicate values for the first index i.
DSA Rust
if i > 0 && nums[i] == nums[1] { continue; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with the next element instead of previous.
Comparing with the same element.
Comparing with the first element always.
✗ Incorrect
We compare current element with the previous to skip duplicates.
3fill in blank
hardFix the error in the while loop condition to move the left pointer correctly.
DSA Rust
while left < right && nums[left] == nums[1] { left += 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with left - 1 which is previous element.
Comparing with right pointer element.
Comparing with the same element.
✗ Incorrect
We compare with the next element to skip duplicates after moving left pointer.
4fill in blank
hardFill both blanks to correctly update the right pointer and skip duplicates.
DSA Rust
while left < right && nums[right] == nums[1] { right [2] 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' which moves right pointer forward incorrectly.
Comparing with right + 1 which is out of bounds.
Using '=' instead of '-='.
✗ Incorrect
We compare with the previous element and decrement right pointer to skip duplicates.
5fill in blank
hardFill all three blanks to correctly push the quadruplet into the result vector.
DSA Rust
result.push(vec![nums[1], nums[2], nums[3], nums[right]]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices or missing one index.
Repeating the same index multiple times.
Using right twice instead of left.
✗ Incorrect
The quadruplet consists of elements at indices i, j, left, and right.
