You are viewing a single comment's thread. Return to all comments →
I am using this java solution but still getting 2 test case failed anyone hlep me , thanks in advance
Map<Character,Integer> ma=new HashMap<>(); for(int i=0;i<s.length();i++) { if(!ma.containsKey(s.charAt(i))) { ma.put(s.charAt(i),1); } else { ma.computeIfPresent(s.charAt(i),(k,v)->++v); } } Integer[] op= ma.values().toArray(Integer[]::new); Arrays.sort(op); if(op[0]==op[op.length-1]) { return "YES"; } if(op[0]==1 && op[1]==op[op.length-1]) { return "YES"; } if(op[0]==op[1] && op[1]==op[op.length-2] && (op[1]==op[op.length-1]-1)) { return "YES"; } return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and the Valid String
You are viewing a single comment's thread. Return to all comments →
I am using this java solution but still getting 2 test case failed anyone hlep me , thanks in advance