algorythms
Trie
LC #336Hard

Palindrome Pairs

Trie
GoogleAmazonBloombergUber

Problem

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

Inputwords = ["abcd","dcba","lls","s","sssll"]
Output[[0,1],[1,0],[3,2],[2,4]]
Why

"abcddcba","dcbaabcd","slls","llssssll" are all palindromes

Hints — reveal one at a time