Not getting what is wrong. Please help

import java.util.;
import java.io.
;
public class ss {

public static void main(String[] args) {
	Scanner sc = new Scanner (System.in);
	int n;
	n=sc.nextInt();
	sc.nextLine();
	String a,b;
	a=sc.nextLine();
	int counter=0;
	int [] arr= {2,3,5,7,11,13,17,19,23,29};
	for(int i=0;i<a.length();i++) {
		for(int j=i+1;j<=a.length();j++) {
			String ss = "";
			ss=a.substring(i,j);
			
			int no = Integer.parseInt(ss);
			//System.out.println(no); //optional
			
			if(no==0 || no==1) {
				continue;
			}
			else {
				for(int l=0;l<arr.length;l++) {
					if(arr[l]==no) {
						counter++;
						i=j+1;
						j=a.length();
					}else if(no>29) {
						for(int d=0;d<arr.length;d++) {
							if(no%arr[d]!=0)
								counter++;
						}
					}
					
				}
			}
			
			}
		}
	
	System.out.println(counter);
}

}

Hi Ashish,
You also have to check weather a digit is previously used in other CB number or not. If yes then you don’t have to increase the counter but if no then you have to increase the counter.

I am still not getting it,
Can you help ?

Hi Ashsih,
Consider input string is 4991. Since 499 and 991 are bot CB numbers your code will print 2. But according to the question you have to print 1 as 99 is repeating both in 499 as well as in 991. You code does not check weather the CB numbers already counted have a sub string or super string similar to one you just found. And hence your code will count extra CB numbers.

Hi Ashish
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.