Palindrome Pairs

Hard
ArrayHash TableStringTrieAirbnbGoogle
Given a list of unique lowercase words, print all ordered index pairs (i, j) where i != j and words[i] + words[j] is a palindrome. Input format: - First line: n - Next n lines: one word per line Print pairs in lexicographic order by i then j, one pair per line as `i j`. Print `EMPTY` if there are no pairs.

Constraints

1 <= n <= 5000
0 <= word length <= 300
Words are unique lowercase strings.

Sample tests

Sample 1

Sample 2

Sign in to submit