Trie
LC #336Hard
Palindrome Pairs
Trie
GoogleAmazonBloombergUberProblem
Find all pairs of indices (i, j) such that words[i] + words[j] is a palindrome.
triestringpalindrome
Constraints
- ›1 ≤ words.length ≤ 5000
- ›0 ≤ words[i].length ≤ 300
- ›words[i] consists of lowercase letters
- ›All words are unique
Example
Input
words = ["abcd","dcba","lls","s","sssll"]Output
[[0,1],[1,0],[3,2],[2,4]]Why
"abcddcba","dcbaabcd","slls","llssssll" are all palindromes