Skip to content

Practice Count Prefix and Suffix Pairs I

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3042
LeetCode Problem

Count Prefix and Suffix Pairs I

Problem Statement

Given words, count pairs of indices i < j for which words[i] is both a prefix and a suffix of words[j]. A prefix begins at the start of the string, and a suffix ends at its end.

Source: Count Prefix and Suffix Pairs I on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["a","aba","ababa","aa"]
Output
4

# Example 2

Input
words = ["pa","papa","ma","mama"]
Output
2

# Example 3

Input
words = ["abab","ab"]
Output
0

Constraints

1 <= words.length <= 50
1 <= words[i].length <= 10
words[i] consists only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Count Prefix and Suffix Pairs I.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.