Weighted Uniform Strings

  • + 0 comments
    function weightedUniformStrings(s: string, queries: number[]): string[] {
        const alphabet = '0abcdefghijklmnopqrstuvwxyz'.split('');
        const availWeights =  new Set<number>()
        const chop = s.split('')
        let mult = 1
        for(let i = 0; i < chop.length; i++) {
            const weight = alphabet.indexOf(chop[i]) * mult;
            availWeights.add(weight);
            if(chop[i+1] !== chop[i]) {
                mult = 1
            } else {
                mult++
            }
        }
        const result: string[] = []
        for(let query of queries) {
            availWeights.has(query) ? result.push('Yes') : result.push('No')
        }
        return result
    }