You are given a 0-indexed string array `words`. Define `isPrefixAndSuffix(str1, str2)` to be true when `str1` is both a prefix and a suffix of `str2`. Return the number of index pairs `(i, j)` with `i < j` such that `isPrefixAndSuffix(words[i], words[j])` is true.
You are given a 0-indexed string array words. Define isPrefixAndSuffix(str1, str2) to be true when str1 is both a prefix and a suffix of str2. Return the number of index pairs (i, j) with i < j such that isPrefixAndSuffix(words[i], words[j]) is true.
Example 1:
Input: {"words":["a","aba","ababa","aa"]}
Output: 4
Constraints:
1≤words.length≤50
1≤words[i].length≤10
words[i] consists only of lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"words":["a","aba","ababa","aa"]}
words: j (later word) · i (earlier word)
0a
1aba
2ababa
3aa
count = 0. Every later word words[j] will be checked against each earlier word words[i].