import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
toh(n,“T1”,“T2”,“T3”);
System.out.println(countMoves(n));
}
public static void toh(int n,String T1,String T2,String T3){
if(n==0){
return;
}
toh(n-1,T1,T3,T2);
System.out.println(“move " +n+” th disc from “+T1+” to "+T2);
toh(n-1,T3,T2,T1);
}
public static int countMoves(int n) {
if (n == 0) return 0;
// count(n-1) + 1 + count(n-1)
return 2 * countMoves(n - 1) + 1;
}
}
Output is correct but all test cases failed
Your output is wrong because as shown in sample output the out put must be in the form :- Move 1th disc from T1 to T3
but your output is not same. Remember if you are writing move instead of Move that will also fail the test case.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.