You are viewing a single comment's thread. Return to all comments →
public static String happyLadybugs(String b) { // Write your code here List<Character> list=new ArrayList<>();
boolean check= b.contains(""); b=b.replaceAll("", ""); char arr[]=b.toCharArray();
for(char c : arr){ list.add(c); } Map<Character,Long> map = list.stream(). collect(Collectors.groupingBy(Function.identity(),Collectors.counting())); Collection<Long> values = map.values(); long count= values.stream().filter(e->e<2).count();
if(check==false){ if(count>0){ return "NO"; } //------------------ for(int i=1;i
if(b.charAt(i)==b.charAt(i-1) || b.charAt(i)==b.charAt(i+1)){ }else{ return "NO"; } } return "YES"; //-------------------- } else{ if(count>0){ return "NO"; }else{ return "YES"; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
Java
boolean check= b.contains(""); b=b.replaceAll("", ""); char arr[]=b.toCharArray();
if(check==false){ if(count>0){ return "NO"; } //------------------ for(int i=1;i