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.
functionsubstrCount(n,s){let_specials=0;constcharr=[...s];for(leti=0;i<n;i++){letspecialChar=charr[i];letnextCharIdx=i+1;letisSpecial=true;while(isSpecial){constnextChar=charr[nextCharIdx];if(!nextChar)break;// eol// check if same char => special (e.g. 'aa' or 'aaa')if(nextChar===specialChar){_specials++;nextCharIdx++;}else{// check for substring with 'special middle char' (e.g. 'aabaa')constlength=nextCharIdx-i;if(nextCharIdx+1+length<=n){// check eolconstafterStr=s.substring(nextCharIdx+1,nextCharIdx+1+length);if([...afterStr].every((c)=>c===specialChar)){_specials++;}}isSpecial=false;}}}return_specials+n;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Special String Again
You are viewing a single comment's thread. Return to all comments →
JS - fast