Count Suffix-Related Word Pairs
Problem statement
You are given an array of strings words. Count unordered index pairs (i, j) with i < j for which either word is a suffix of the other.
Equal words qualify.
Function
countSuffixPairs(words: String[]) → longExamples
Example 1
words = ["a","ba","cba","x"]return = 3a is a suffix of ba and cba, and ba is a suffix of cba.
Example 2
words = ["x","x","yx"]return = 3The equal x values qualify, and each is a suffix of yx.
Constraints
0 <= words.length <= 20000 <= words[i].length <= 1000- Words contain lowercase English letters.