Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 1.25 KB

_2416. Sum of Prefix Scores of Strings.md

File metadata and controls

52 lines (37 loc) · 1.25 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : September 25, 2024

Last updated : September 25, 2024


Related Topics : Array, String, Trie, Counting

Acceptance Rate : 60.59 %


Solutions

Python

class Solution:
    def sumPrefixScores(self, words: List[str]) -> List[int]:
        trie = {}

        for i, word in enumerate(words):
            curr = trie
            for c in word :
                if c not in curr :
                    curr[c] = {}
                curr = curr[c]
                curr[False] = curr.get(False, 0) + 1
        output = []

        for word in words :
            curr = trie
            output.append(0)
            for i, c in enumerate(word, 1) :
                curr = curr[c]

                if False in curr :
                    output[-1] += curr[False]

        return output