Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the input slice before processing.
DSA Go
sort.[1](nums)Attempts:
3 left
💡 Hint
Common Mistakes
Using sort.Reverse which requires a different type.
Using sort.Float64s which is for float slices.
Using sort.Strings which is for string slices.
✗ Incorrect
We use sort.Ints to sort a slice of integers in ascending order.
2fill in blank
mediumComplete the code to skip duplicate values for the first element in the triplet.
DSA Go
if i > 0 && nums[i] == nums[[1]] { continue }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i+1 which looks ahead and may cause index out of range.
Using 0 which always compares to the first element.
Using len(nums)-1 which is the last element, unrelated here.
✗ Incorrect
We compare the current element nums[i] with the previous element nums[i-1] to skip duplicates.
3fill in blank
hardFix the error in the two-pointer loop condition to avoid index out of range.
DSA Go
for left < right && [1] < len(nums) && right < len(nums) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using i which is fixed in outer loop and unrelated here.
Using right which is already checked.
Using 0 which is always valid and useless here.
✗ Incorrect
We check that left pointer is less than length to avoid out of range errors.
4fill in blank
hardFill both blanks to correctly move pointers after finding a valid triplet.
DSA Go
for left < right && nums[left] == nums[[1]] { left[2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using left-1 which moves pointer backward incorrectly.
Using -- which decrements pointer causing infinite loop.
✗ Incorrect
We compare nums[left] with the next element nums[left+1] and increment left pointer to skip duplicates.
5fill in blank
hardFill all three blanks to correctly update pointers based on sum comparison.
DSA Go
if sum < 0 { left[1] } else if sum > 0 { right[2] } else { result = append(result, []int{nums[i], nums[left], nums[right]}) left[3] right-- }
Attempts:
3 left
💡 Hint
Common Mistakes
Using += or -= which require a number and are not valid for pointer increments.
Using -- on left pointer when sum < 0 which moves pointer backward incorrectly.
✗ Incorrect
When sum is less than zero, move left pointer forward with ++; when sum is greater, move right pointer backward with --; after finding a triplet, move left pointer forward with ++.
