You are viewing a single comment's thread. Return to all comments →
JavaScript:
Time complexity - o(n) Space complexity - o(n)
function weightedUniformStrings(s, queries) { let prev = ''; let weight = 0; const possibility = {}; for(let el of s) { if(el === prev) weight++; else { prev = el; weight = 1; } const val = (el.charCodeAt() - 96) * weight; possibility[val] = el; } let out = []; for(let query of queries) out.push(possibility[query] ? "Yes" : "No") return out; }
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
JavaScript:
Time complexity - o(n) Space complexity - o(n)