dsa1 min read
Prefix and Suffix Search — Combined Key Trie
Find word with given prefix AND suffix. Insert 'suffix#word' for each suffix of each word into trie; query combines prefix+suffix search.
Read →
1575 articles
Find word with given prefix AND suffix. Insert 'suffix#word' for each suffix of each word into trie; query combines prefix+suffix search.
For each word, sum up how many other words share each of its prefixes. Trie with prefix count at each node; query each word's prefix sum.
Find all words that can be formed by concatenating two or more words from the same list. Build trie, then run word break DP on each word.
Encode word list as shortest string where each word is a suffix. Words that are suffixes of others need not be separately encoded. Use trie of reversed words.
Implement insert(key, val) and sum(prefix) returning sum of values for all keys with given prefix. Trie with value at end node.