Tower of Hanoi Problem Statement
You have three rods numbered from 1 to 3, and 'N' disks initially stacked on the first rod in increasing order of their sizes (largest disk at the bottom). Your task is to move the 'N' disks to another rod (either rod 2 or rod 3) by following the rules below in less than 2N moves.
1. Only one disk can be moved at a time.
2. Larger disks cannot be placed on top of smaller disks.
3. Disks can only be moved from the top of a rod.
Note:
The initial size of the 'i'th disk from the top of the stack is equal to 'i', meaning the bottom disk has size 'N', the disk above it has size 'N-1', and so forth, with the top disk being size 1.
Example:
Input:
The first line contains an integer 'T', the number of test cases. Each test case contains a single integer 'N', representing the number of disks.
Output:
For each test case, output a 2-D array/list where each row contains two integers. The first integer is the number of the rod from which the topmost disk is moved, and the second integer is the rod number to which the disk is placed. The result is '1' if all disks are successfully moved to rod 2 or 3, otherwise, '0'.
Note:
Printing is not required; simply implement the function to return the answer.
Constraints:
- 1 <= T <= 5
- 1 <= N <= 12
- 'T' represents the number of test cases, 'N' represents the number of disks.
- Time Limit: 1 second

AnswerBot
4mo
Tower of Hanoi problem where 'N' disks need to be moved to another rod following specific rules in less than 2^N moves.
Implement a recursive function to move disks from one rod to another following th...read more
Help your peers!
Add answer anonymously...
VMware Software Member Technical Staff interview questions & answers
A Member Technical Staff was asked Q. Convert Array to Min Heap Task Given an array 'ARR' of integers with 'N' element...read more
A Member Technical Staff was asked Q. Tower of Hanoi Problem Statement You have three rods numbered from 1 to 3, and '...read more
A Member Technical Staff was asked Q. What is a page fault?
Popular interview questions of Member Technical Staff
A Member Technical Staff was asked Q1. Convert Array to Min Heap Task Given an array 'ARR' of integers with 'N' element...read more
A Member Technical Staff was asked Q2. Tower of Hanoi Problem Statement You have three rods numbered from 1 to 3, and '...read more
A Member Technical Staff was asked Q3. What is a page fault?
>
VMware Software Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

