Problem Brief
Suffix Pairs
OA
Given an array of strings words, find the number of pairs where either the strings are equal or one string ends with another. In other words, find the number of such pairs (i, j) (0 ≤ i < j < words.length) that words[i] is a suffix of words[j].
1Example 1
Input
words = ["hack", "hackhour", "jammon", "backgammon", "comeback", "come", "door"]
Output
3
Explanation
The relevant pairs are:
words[0] = "hack"andwords[1] = "comeback"words[1] = "hackhour"andwords[6] = "door"words[2] = "jammon"andwords[3] = "backgammon"
2Example 2
Input
words = ["cha", "a", "a", "b", "ba", "ca"]
Output
8
Explanation
The relevant pairs are:
words[0] = "cha"andwords[1] = "a"words[0] = "cha"andwords[2] = "a"words[0] = "cha"andwords[4] = "ba"words[1] = "a"andwords[2] = "a"words[1] = "a"andwords[4] = "ba"words[1] = "a"andwords[5] = "ca"words[2] = "a"andwords[4] = "ba"words[2] = "a"andwords[5] = "ca"
Constraints
Limits and guarantees your solution can rely on.
1 ≤ words.length ≤ 1051 ≤ words[i].length ≤ 10