Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the left pointer at the start of the array.
DSA Go
left := [1]Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 or -1 causes skipping the first element.
Setting left to len(nums) causes out-of-range errors.
✗ Incorrect
The left pointer should start at index 0 to begin sorting from the start.
2fill in blank
mediumComplete the code to swap elements at indices left and current.
DSA Go
nums[[1]], nums[current] = nums[current], nums[[1]]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with right pointer instead of left.
Swapping current with itself does nothing.
✗ Incorrect
We swap the element at left with the element at current to move 0s to the front.
3fill in blank
hardFix the error in the loop condition to continue while current is less than or equal to right.
DSA Go
for current [1] right {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '>=' causes the loop to never run or run incorrectly.
Using '<' misses the last element at right.
✗ Incorrect
The loop should run while current is less than or equal to right to process all elements.
4fill in blank
hardFill both blanks to correctly update pointers after swapping a 0.
DSA Go
nums[[1]], nums[current] = nums[current], nums[[1]] left[2]
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing right instead of left after swapping 0.
Not incrementing any pointer causes infinite loop.
✗ Incorrect
After swapping with left, increment left to move boundary forward.
5fill in blank
hardFill all three blanks to correctly swap with right pointer and update pointers after encountering a 2.
DSA Go
nums[[1]], nums[current] = nums[current], nums[[1]] right[2] [3]
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing right instead of decrementing.
Not moving current pointer after swap causes infinite loop.
✗ Incorrect
Swap with right, decrement right, and increment current to continue sorting.
