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.
publicstaticstringisValid(strings){int[]qs=newint['z'-'a'+1];foreach(charcins){qs[c-'a']++;}qs=qs.Where(x=>x>0).ToArray();boolok=false;if(qs.Length>0){vargs=qs.GroupBy(x=>x).Select(x=>new{q=x.Key,c=x.Count()}).OrderBy(x=>x.q).ToArray();ok=gs.Length==1||(gs.Length==2&&((gs[0].c==1)||(gs[0].q==gs[1].c&&Math.Abs(gs[0].c-gs[1].q)<2)||(gs[1].c==1&&(gs[1].q-gs[0].q)==1)));/*foreach(var g in gs){Console.WriteLine(string.Concat(g.q,"=",g.c));}*/}returnok?"YES":"NO";}
Cookie support is required to access HackerRank
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 →
c# version passed in all tests