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;
return 2 * countMoves(n - 1) + 1;
}
}
Here i am getting the exact output but still all the test cases are failed
Your code is not coreect Please update your code. try running your code for input 3 your output is always coming 3 instead for 3 input output should be
Move 1th disc from T1 to T2
Move 2th disc from T1 to T3
Move 1th disc from T2 to T3
Move 3th disc from T1 to T2
Move 1th disc from T3 to T1
Move 2th disc from T3 to T2
Move 1th disc from T1 to T2
7
Think on your logic and if you still face any issue please let me know.