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.
stringhappyLadybugs(stringb){inti=0;boolf=false;intlookup[31]={0};intlen=b.length();for(i=0;i<len;++i){lookup[b[i]-65]++;}for(i=0;i<26;++i){if(lookup[i]==1)return"NO";}if(lookup[30]==0){// We don't have any '_'// Check if str is already arrangedcharprev=b[0];intocc=1;for(i=1;i<len;++i){if(b[i]==prev){++occ;}elseif(occ==1)return"NO";elseocc=1;prev=b[i];}return"YES";// string is arranged in desired order}return"YES";// string can be arranged in desired order}
Cookie support is required to access HackerRank
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 →