We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
unordered_map<char,int>ladybug;intflag=0;//counting frequency of characterfor(inti=0;i<b.size();i++){ladybug[b[i]]++;}//checking the count of the character greater than 1if(ladybug.size()>1){for(inti=0;i<ladybug.size();i++){charc=i+65;if(ladybug[c]==1&&c!='_')return"NO";}}//checking if any possible chance to switch for(autoi:ladybug){if(i.first=='_'){flag=1;break;}}// checking it is sorted or not if there is no chance to switchif(flag==0){for(inti=0;i<b.size();i++){if(b[i]==b[i+1]||b[i]==b[i-1]){flag=1;}else{flag=0;break;}}}returnflag==0?"NO":"YES";
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →