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.
publicstaticstringhappyLadybugs(stringb){Dictionary<char,int>map=newDictionary<char,int>();// Case for checking if string contains all "_"boolcheckUnderScore=false;boolcontainsUnderScore=false;for(inti=0;i<b.Length;i++){if(b[i]>='A'&&b[i]<='Z'){checkUnderScore=true;}else{containsUnderScore=true;}}if(checkUnderScore==false){return"YES";}if(containsUnderScore==false){intleft=0;intright=0;for(inti=1;i<b.Length-1;i++){left=i-1;right=i+1;if(b[left]!=b[i]&&b[right]!=b[i]){return"NO";}}}// Other Casesfor(inti=0;i<b.Length;i++){if(map.ContainsKey(b[i])){map[b[i]]++;}else{map[b[i]]=1;}}foreach(variteminmap){if(item.Key!='_'&&item.Value==1){return"NO";}}return"YES";}
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 →
C# Solution: