Count subsequence


what is wrong in this code?

your approach seems to be right

modulus is given
means ans can larger
so pls take long

It is showing error ,i have changed long instead of int

it is not passing the testcases

pls see the changes which i have made
approach was right
just i have the int arry to long
and used the modulus oper

hope this will help u
pls rate my work
pls

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);

	int t = sc.nextInt();
    sc.nextLine();
	long[] ans =new long[t];
	for(int i =0;i<t;i++) {
		String x = sc.nextLine();
		 long count = countSub(x);
		 ans[i]=count;
	}
	for(int i =0;i<t;i++) {
		System.out.println(ans[i]%1000000007);
	}
}
public static long countSub(String str) {
	
	 final int MAX_LENGTH=256;
	 int mod=1000000007;
	 int[] last = new int[MAX_LENGTH];
	 Arrays.fill(last, -1);
	 
	 int n = str.length();
	 
	 long[] dp = new long[n+1];
	 
	 dp[0]=1;
	 
	 for(int i =1;i<=n;i++) {
		 
		 dp[i] = (2*dp[i-1])%mod;
		 
		 
		 if(last[(int)str.charAt(i-1)]!= -1) {
			 dp[i] = (((dp[i] - dp[last[(int)str.charAt(i-1)]]))+mod)%mod;
		 }
		 
		 last[(int)str.charAt(i-1)]= i-1;
	 }
	 
	 return dp[n];
}

}

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.