Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the move from source to destination rod.
DSA Typescript
console.log(`Move disk from [1] to destination`);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'destination' instead of 'source' for the starting rod.
Using 'disk' which is not a rod name.
✗ Incorrect
The move is from the source rod to the destination rod, so 'source' is correct.
2fill in blank
mediumComplete the recursive call to move n-1 disks from source to auxiliary rod.
DSA Typescript
hanoi([1] - 1, source, auxiliary, destination);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'n - 1 - 1' or other incorrect expressions.
Passing a fixed number like 1 instead of the variable.
✗ Incorrect
We call hanoi with n-1 disks, so the argument should be 'n'.
3fill in blank
hardFix the error in the base case condition to stop recursion when no disks remain.
DSA Typescript
if (n [1] 0) return;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'n > 0' which causes infinite recursion.
Using 'n == 0' which misses negative values.
✗ Incorrect
The recursion stops when n is less than or equal to 0, so 'n <= 0' is correct.
4fill in blank
hardFill both blanks to move n-1 disks from auxiliary to destination rod after moving the largest disk.
DSA Typescript
hanoi(n [1] 1, [2], destination, source);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' for disk count.
Using 'source' instead of 'auxiliary' for the starting rod.
✗ Incorrect
We move n-1 disks, so use 'n - 1', and the disks move from auxiliary rod.
5fill in blank
hardFill all three blanks to complete the Tower of Hanoi recursive function call sequence.
DSA Typescript
hanoi([1] - 1, source, [2], destination); console.log(`Move disk from [3] to destination`); hanoi([1] - 1, [2], destination, source);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up source and auxiliary rods in recursive calls.
Incorrect disk count in recursive calls.
✗ Incorrect
We move n-1 disks from source to auxiliary, then move disk from source to destination, then move n-1 disks from auxiliary to destination.