Skip to content
CampusEduX

Tower of Hanoi

Mediumjavapythonccppjavascript

Solve the Tower of Hanoi for N disks using three rods named A, B and C. Move all disks from rod A to rod C, never placing a larger disk on a smaller one.

Input Format

A single line containing the integer N.

Output Format

Print the sequence of moves, one per line, each as X -> Y meaning "move the top disk from rod X to rod Y".

Related Problems

  • Generate All Subsets
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Generate All Permutations
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Rat in a Maze
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...