You are viewing a single comment's thread. Return to all comments →
Java solution:-
static void gameOfThrones(String s) { int i,freq,count=0,even=0,odd=0; char ch; boolean flag = false; HashSet<Character> set = new LinkedHashSet(); for(i=0;i<s.length();i++) set.add(s.charAt(i)); ArrayList<Character> al = new ArrayList(); for(i=0;i<s.length();i++) al.add(s.charAt(i)); for(Object o:set) { ch = (char)o; freq = Collections.frequency(al, ch); if(s.length()%2==0) { if(freq%2!=0) { flag = false; break; } else { flag = true; continue; } } else { if(freq%2==0) even++; else odd++; } if(even==set.size()-1) flag=true; else flag=false; } if(flag==false) System.out.println("NO"); else System.out.println("YES"); }
Seems like cookies are disabled on this browser, please enable them to open this website
Game of Thrones - I
You are viewing a single comment's thread. Return to all comments →
Java solution:-