You are viewing a single comment's thread. Return to all comments →
int n = s.length(); int[] arr = new int[27];
int max_size=0; int size=0; for(int i=0;i<n;i++) { arr[(int)s.charAt(i)-96]++; } for(int i=1;i<27;i++) { if(arr[i]!=0) { char first = (char)(i+96); for(int j=i+1;j<27;j++) { if(arr[j]!=0) { char second = (char)(j+96); StringBuilder sb = new StringBuilder(); size=0; loop: for(int k=0;k<n;k++) { if(s.charAt(k)==first) { if(sb.toString().length()==0) { sb.append(first); size++; } else { if(sb.toString().charAt(size-1)==first) { break loop; } else { sb.append(first); size++; } } } else if(s.charAt(k)==second) { if(sb.toString().length()==0) { sb.append(second); size++; } else { if(sb.toString().charAt(size-1)==second) break loop; else { sb.append(second); size++; } } } if(k==n-1) { System.out.println(sb.toString()); if(sb.toString().length()>max_size) max_size=sb.toString().length(); } } } } } } return max_size;
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
int n = s.length(); int[] arr = new int[27];