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.
functionisValid(s:string){// Write your code hereletfrequencies=newMap<string,number>();for(leti=0;i<s.length;i++){letcharFreq=0;if(frequencies.has(s[i])){charFreq=frequencies.get(s[i])??0;}charFreq++;frequencies.set(s[i],charFreq);}constvalues=[...frequencies.values()];letpivot=values[0];letcharOperations=0;for(leti=0;i<values.length;i++){if(pivot!==values[i]){charOperations+=Math.abs(pivot-values[i]);}}returncharOperations>1?'NO':'YES'}
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 →
Test 7 and 13 failing