Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Tower of Hanoi with 6 disks, moving all disks from peg A to peg C using peg B as the spare (standard rules). How many moves does the smallest disk (disk 1) make in total?

  1. A. 63
  2. B. 32
  3. C. 64
  4. D. 16

Correct answer: B. 32

Disk k moves 2^(n−k) times, so the smallest disk moves 2⁵ = 32 times (every other move). The total move count is 2⁶ − 1 = 63, 2⁶ = 64 is off by one, and 16 is the move count of disk 2.

More Coding Interview Problems questions

Exams that ask this topic