Problem
Ask
Submissions

Problem: Palindrome Pairs

Medium
30 min
Discover how to find all valid palindrome pairs within an array of unique strings by using efficient trie implementations. This lesson helps you understand and apply trie structures to check concatenated words for palindromes with optimal time complexity. Practice coding solutions that meet interview standards and improve your problem-solving skills with advanced string handling techniques.

Statement

You are given a 0-indexed array of unique strings called words.

A palindrome pair is defined as a pair of indexes (i, j) where both i and j are within the valid range of the list of words (that is, 00 \leq i, j << words.length), and i is not equal to j. The key condition is that when the word at index i is concatenated with the word at index j (forming words[i] + words[j]), the resulting string must be a palindrome.

Your task is to return all valid palindrome pairs as a list of index pairs.

Additionally, your solution must have a time complexity of O(sum ofO(\text{sum of} words.length)).

Constraints:

  • 11 \leq words.length 1000\leq 1000

  • 00 \leq words[i].length 300\leq 300

  • words[i] consists of lowercase English letters

  • All strings in words unique

Problem
Ask
Submissions

Problem: Palindrome Pairs

Medium
30 min
Discover how to find all valid palindrome pairs within an array of unique strings by using efficient trie implementations. This lesson helps you understand and apply trie structures to check concatenated words for palindromes with optimal time complexity. Practice coding solutions that meet interview standards and improve your problem-solving skills with advanced string handling techniques.

Statement

You are given a 0-indexed array of unique strings called words.

A palindrome pair is defined as a pair of indexes (i, j) where both i and j are within the valid range of the list of words (that is, 00 \leq i, j << words.length), and i is not equal to j. The key condition is that when the word at index i is concatenated with the word at index j (forming words[i] + words[j]), the resulting string must be a palindrome.

Your task is to return all valid palindrome pairs as a list of index pairs.

Additionally, your solution must have a time complexity of O(sum ofO(\text{sum of} words.length)).

Constraints:

  • 11 \leq words.length 1000\leq 1000

  • 00 \leq words[i].length 300\leq 300

  • words[i] consists of lowercase English letters

  • All strings in words unique