FunctionRacerProblemsRace

Count Prefixes of a Given String

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

A prefix of s is a piece that starts at its first character (the empty piece does not appear in words). Return how many entries of words are a prefix of s. Equal entries are counted each time they appear.

Example 1

words ["a","b","c","ab","bc","abc"]
s "abc"
returns 3

a, ab, abc are prefixes.

Example 2

words ["a","a"]
s "aa"
returns 2

Both copies of a count.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems