Skip to content

Practice Count Prefixes of a Given String

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

Easy#2255
LeetCode Problem

Count Prefixes of a Given String

Problem Statement

You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters. Return the number of strings in words that are a prefix of s. A prefix of a string is a substring that occurs at the beginning of the string. A substring is a contiguous sequence of characters within a string.

Source: Count Prefixes of a Given String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["a","b","c","ab","bc","abc"], s = "abc"
Output
3

# Example 2

Input
words = ["a","a"], s = "aa"
Output
2

Constraints

1 <= words.length <= 1000
1 <= words[i].length, s.length <= 10
words[i] and s consist of lowercase English letters only.

Related LeetCode Problems

Practice more problems similar to Count Prefixes of a Given String.

Review your practice with PhantomCodeAI

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