Dsa
Recursion
Medium
Tower of Hanoi Moves
Implement the Tower of Hanoi problem. Given a number of disks, print the sequence of moves required to transfer all disks from the source rod to the target rod using an auxiliary rod. The function should print out each move in the format "Move disk from source to target".
Input:
A single integer n, the number of disks (1 <= n <= 10).
Output:
Print each move on a new line.
Example:
Input:
2
Output:
Move disk from A to C
Move disk from A to B
Move disk from C to B
Key concepts
recursionmathematicsalgorithm design
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now