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:string,queries:number[]):string[]{/** * idea is calculate the weight of each character and it pairs * then compare it with query, any included are 'Yes' orelse 'No' * * example: * [s] 'abccddde' * [a b c cc d dd ddd e] * [ws] will be [1 2 3 6 4 8 12 5] * [queries] [1, 3, 12, 5, 9, 10] * x x x x _ _ * [return] Y Y Y Y N N */letws=[]letcl=nullletcc=0for(leti=0;i<s.length;i++){letcd=s.charCodeAt(i)-97+1if(!cl||cl!=cd){cl=cd;cc=0}ws.push(cl*++cc)}returnqueries.map(query=>ws.includes(query)?'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 →
My answer in Typpescript, simple, noted