Tower of Hanoi Problem
Tower of Hanoi Problem — ExecCode Medium DSA Practice
Solve the Tower of Hanoi problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Move n disks from peg A to peg C using helper peg B. Rules: 1. Only one disk may be moved at a time. 2. A larger disk may never sit on a smaller disk. Minimum moves = 2^n - 1. For n=4 → 15 moves.
Examples
Input n = 1; Output ["A→C"]. Input n = 2; Output ["A→B", "A→C", "B→C"]. Input n = 3; Output ["A→C", "A→B", "C→B", "A→C", "B→A", "B→C", "A→C"]
Constraints
1 <= n <= 10 for visualization (exponential moves)
Practice Tower of Hanoi free on ExecCode. Browse DSA problems, topic map, and placement guides.