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.
functionweightedUniformStrings(s,queries){constvalidWeights=newSet();letcurrentChar='';letcurrentWeight=0;letcount=0;for(leti=0;i<s.length;i++){if(s[i]===currentChar){count++;}else{currentChar=s[i];count=1;currentWeight=s.charCodeAt(i)-96;// 'a' has ASCII value 97}validWeights.add(currentWeight*count);}returnqueries.map(q=>validWeights.has(q)?'Yes':'No');}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →