Recursion subsequences

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];

}
}
code compiled but run time error showing…i.e testcases patially executed

@karthik1989photos bro first of all, attach correct question name while asking doubts your solution is for count subsequences and you are attaching Recursion-Subsequences as question.
I have checked your submission you are basically submitting the code in recursion subsequences but the code is for count subsequences which is entirely different dp problem.

Same problem was with your string compression one, bro are you reading the question correctly or not?
Your code is passing all test cases for count subsequences but why are you submitting this code for recursion subsequences, its a simple recursive problem.

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class all_subsequences_lexicoOrder {

public static ArrayList ans;

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	for (int i = 0; i < n; i++) {
		ans=new ArrayList<>();
		String str = sc.next();
		PrintSS(str, "");
		for (int p = 0; p < ans.size() - 1; p++) {
            for (int q= p + 1; q< ans.size(); q++) {
                if (ans.get(p).compareTo(ans.get(q)) > 0) {
                    Collections.swap(ans, p,q);
                }
            }
        }
        for (int s = 0; s < ans.size(); s++) {
            System.out.println(ans.get(s));
        }
	}

}

public static void PrintSS(String str, String result) {
	if (str.length() == 0) {
		ans.add(result);
		return;
	}

	char cc = str.charAt(0);
	String ros = str.substring(1);
	PrintSS(ros, result);
	PrintSS(ros, result + cc);
}

}
i tried again this time testcases running partially,plz correct code

sir i tried a lot plz provide me the solution

@karthik1989photos Here is ya corrected submission but just tell me that did you even read about the input format? Only a string is given as input you are first taking n as input then String.

Then you tried to sort it alphabetically, that wasn’t also asked then you did not print the count, your code will not even run for sample. So what’s up with your solutions bro?

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

public static ArrayList ans;

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
		ans=new ArrayList<>();
		String str = sc.next();
		PrintSS(str, "");
        for (int s = 0; s < ans.size(); s++) {
            System.out.print(ans.get(s) + " ");
        }

		System.out.println();
		System.out.print(ans.size());
		

}

public static void PrintSS(String str, String result) {
	if (str.length() == 0) {
		ans.add(result);
		return;
	}

	char cc = str.charAt(0);
	String ros = str.substring(1);
	PrintSS(ros, result);
	PrintSS(ros, result + cc);
}

}

And do mark all the previous and this doubt as well and rate full bro, keep coding!

on submitting code it is showing this type of error

Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

@karthik1989photos That copy pasting changed the format here i have saved on ide.


Also resolve this and ya previous doubts