You are viewing a single comment's thread. Return to all comments →
public static int alternate(String s) { // Write your code here int count=0; boolean b=true; int result=0; char arr[]=s.toCharArray(); List<Character> list =new ArrayList<>(); for(char c:arr){ list.add(c); } list=list.stream().distinct().collect(Collectors.toList()); String st=s; for(int i=0;i<list.size()-1;i++){ for(int j=i+1;j<list.size();j++){ st=s; st=st.replaceAll("[^"+list.get(i) +list.get(j) +"]", ""); for(int k=0;k<st.length()-1;k++){ if(st.charAt(k)==st.charAt(k+1)){ b=false; count=0; break; } b=true; } if(b){ count=st.length(); if(count>result){ result=count; b=true; } } } } return result; }
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 →
Java