Question bank › Stack
Dsa Stack Medium

Tower of Hanoi Solver

Implement a program to solve the Tower of Hanoi problem using stacks. You should simulate the movement of disks between three rods. The disks are initially stacked in decreasing order on the first rod. You should print the sequence of moves needed to transfer all disks to the third rod. Input The input consists of a single integer n, the number of disks. Output Print the sequence of moves required to solve the Tower of Hanoi, where each move is specified as 'Move disk from rod X to rod Y'. Example Input: 2 Output: Move disk from rod 1 to rod 3 Move disk from rod 1 to rod 2 Move disk from rod 3 to rod 2

Key concepts

stackrecursionalgorithm

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.