You, leetcode
Back

LeetCode 820 (Medium). Short Encoding of Words

I'm a sucker for any coding challenges involving words. Here's one that is basically about counting how many words are suffixes of other words. I wrote a trie with an idiosyncratic add() method that tracks the number of words that aren't prefixes of any other words and how many characters are in those non-prefix words. Those two details are used to formulate the single integer answer that the problem asks for. Fun to write!

https://leetcode.com/problems/short-encoding-of-words/discuss/2172722/Java-12ms-beats-99.4-uses-trie-tracks-number-of-chars-in-trie-and-number-of-words