
Asked in MakeMyTrip
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
Be the first one to answer
Add answer anonymously...
Top Full Stack Developer Interview Questions Asked at MakeMyTrip
Q. Make Array Elements Equal Problem Statement Given an integer array, your objecti...read more
Q. Minimum Operations Problem Statement You are given an array 'ARR' of size 'N' co...read more
Q. Square Root with Decimal Precision Problem Statement You are provided with two i...read more
Interview Questions Asked to Full Stack Developer at Other Companies
Top Skill-Based Questions for MakeMyTrip Full Stack Developer
Web Development Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
JavaScript Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

