Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the move from source to destination peg.
DSA Go
fmt.Println("Move disk from peg", [1], "to peg", dest)
Attempts:
3 left
💡 Hint
Common Mistakes
Using dest instead of source for the starting peg.
Printing disk instead of peg number.
✗ Incorrect
The move is from the source peg to the destination peg, so we print the source variable.
2fill in blank
mediumComplete the recursive call to move n-1 disks from source to temp peg.
DSA Go
towerOfHanoi([1], source, temp, dest)Attempts:
3 left
💡 Hint
Common Mistakes
Using n instead of n-1 in recursive calls.
Using n+1 which is invalid.
✗ Incorrect
We move n-1 disks to the temporary peg before moving the largest disk.
3fill in blank
hardFix the error in the recursive call to move n-1 disks from temp to dest peg.
DSA Go
towerOfHanoi([1], temp, dest, source)Attempts:
3 left
💡 Hint
Common Mistakes
Using n instead of n-1 causing infinite recursion.
Using 0 which skips the move.
✗ Incorrect
We move n-1 disks from temp to destination peg after moving the largest disk.
4fill in blank
hardFill both blanks to complete the base case condition and return statement.
DSA Go
if n [1] 0 { [2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '==' which may cause extra calls.
Using continue instead of return causing infinite recursion.
✗ Incorrect
The base case is when n equals 0, then the function returns immediately.
5fill in blank
hardFill both blanks to complete the recursive Tower of Hanoi function call sequence.
DSA Go
towerOfHanoi([1], source, temp, dest) fmt.Println("Move disk from peg", source, "to peg", dest) towerOfHanoi([2], temp, dest, source)
Attempts:
3 left
💡 Hint
Common Mistakes
Using n instead of n-1 causing incorrect recursion.
Using 0 or 1 which does not solve the problem correctly.
✗ Incorrect
Both recursive calls move n-1 disks before and after moving the largest disk.
