Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the input list before processing.
DSA Python
nums = [1, 0, -1, 0, -2, 2] nums.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using reverse() instead of sort()
Trying to append or pop elements here
✗ Incorrect
Sorting the list helps to efficiently find quadruplets and avoid duplicates.
2fill in blank
mediumComplete the code to skip duplicate values for the first pointer i.
DSA Python
for i in range(len(nums) - 3): if i > 0 and nums[i] == nums[[1]]: continue
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with i + 1 which is the next element
Comparing with 0 index always
✗ Incorrect
To skip duplicates, compare current element with the previous one at i-1.
3fill in blank
hardFix the error in the while loop condition to avoid infinite loops.
DSA Python
while left < right: total = nums[i] + nums[j] + nums[left] + nums[right] if total == target: result.append([nums[i], nums[j], nums[left], nums[right]]) left += 1 right -= 1 while left < right and nums[left] == nums[[1]]: left += 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using left + 1 which causes skipping too far
Using right pointers incorrectly
✗ Incorrect
We compare nums[left] with the previous left value at left - 1 to skip duplicates.
4fill in blank
hardFill both blanks to skip duplicates for the second pointer j.
DSA Python
for j in range(i + 1, len(nums) - 2): if j > i + 1 and nums[j] == nums[[1]]: continue left, right = j + 1, len(nums) - 1 while left < right: # code to find quadruplets if total == target: # after adding quadruplet while left < right and nums[right] == nums[[2]]: right -= 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using j + 1 instead of j - 1 for skipping duplicates
Using right + 1 instead of right - 1 for skipping duplicates
✗ Incorrect
To skip duplicates for j, compare with previous j-1; for right pointer, compare with right-1.
5fill in blank
hardFill all three blanks to complete the dictionary comprehension that counts quadruplets by their sum.
DSA Python
quadruplet_sums = { [1]: [2] for quad in quadruplets if sum(quad) [3] target } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' in the condition
Swapping key and value in the dictionary comprehension
✗ Incorrect
We create a dictionary with sum(quad) as key and quad as value, filtering sums equal to target.