264. Palindrome Pairs (Count)

HardStringString

Given a list of unique words, return the number of ordered pairs (i, j) with i != j such that the concatenation words[i] + words[j] is a palindrome. Input: a JSON array of strings.

Input: JSON array of strings.

Output: Integer — count of palindrome pairs.

Examples

Example 1
Input: ["abcd","dcba","lls","s","sssll"]
Output: 4
Explanation: Pairs like (0,1),(1,0),(3,2),(2,4).
Example 2
Input: ["bat","tab","cat"]
Output: 2
Explanation: (0,1) and (1,0).
Example 3
Input: ["a",""]
Output: 2
Explanation: 'a'+''='a' and ''+'a'='a'.

Constraints

Asked by

GoogleAmazonMicrosoftMeta
Solve this problem in the editor →