0
0
DSA Typescriptprogramming~10 mins

Tower of Hanoi Problem in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aauxiliary
Bdestination
Csource
Ddisk
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'destination' instead of 'source' for the starting rod.
Using 'disk' which is not a rod name.
2fill in blank
medium

Complete 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'
A0
Bn - 1
C1
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'n - 1 - 1' or other incorrect expressions.
Passing a fixed number like 1 instead of the variable.
3fill in blank
hard

Fix 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'
A>
B<=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'n > 0' which causes infinite recursion.
Using 'n == 0' which misses negative values.
4fill in blank
hard

Fill 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'
A-
B+
Cauxiliary
Dsource
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' for disk count.
Using 'source' instead of 'auxiliary' for the starting rod.
5fill in blank
hard

Fill 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'
An
Bauxiliary
Csource
Ddestination
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up source and auxiliary rods in recursive calls.
Incorrect disk count in recursive calls.