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 on an int slice.
Using sort.Strings on an int slice.
✗ Incorrect
We use sort.Ints to sort a slice of integers in Go.
2fill in blank
mediumComplete the code to skip duplicate elements for the first index i.
DSA Go
if i > 0 && nums[i] == nums[[1]] { continue }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with nums[i+1] which may cause index out of range.
Comparing with nums[0] which is not the previous element.
Comparing with nums[len(nums)-1] which is unrelated.
✗ Incorrect
We compare nums[i] with nums[i-1] to skip duplicates at index i.
3fill in blank
hardFix the error in the two-pointer loop condition to avoid infinite loops.
DSA Go
for left < [1] { // loop body }
Attempts:
3 left
💡 Hint
Common Mistakes
Using left < left which never advances.
Using left < len(nums) which may cause wrong logic.
Using left < i which is unrelated.
✗ Incorrect
The loop continues while left is less than right to avoid overlap.
4fill in blank
hardFill both blanks to correctly move pointers after finding a quadruplet.
DSA Go
left++ for left < right && nums[left] [1] nums[left-1] { left[2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == causes skipping wrong elements.
Decrementing left pointer causes infinite loop.
✗ Incorrect
We move left pointer forward skipping duplicates by checking equality and incrementing.
5fill in blank
hardFill all three blanks to append the quadruplet and move both pointers skipping duplicates.
DSA Go
result = append(result, []int[1], [2], [3], nums[right]}) left++ right-- for left < right && nums[left] == nums[left-1] { left++ } for left < right && nums[right] == nums[right+1] { right-- }
Attempts:
3 left
💡 Hint
Common Mistakes
Using nums[right] twice in the quadruplet.
Not including nums[j] or nums[i].
Appending wrong indices causing incorrect quadruplets.
✗ Incorrect
We append the quadruplet with nums[i], nums[j], nums[left], nums[right] and then move pointers skipping duplicates.
