Ctrl K

Typed-So-Far Matches

Easy
A search box remembers the user's earlier drafts in the list drafts. The user has typed the query query. A draft matches if query begins with it exactly (including when the draft equals the whole query). Return the number of matching drafts. Repeated drafts each count separately.
Example 1
drafts=["c", "ca", "cat", "cab", "at"], query="cats" → 3

The query "cats" starts with "c", "ca" and "cat". "cab" differs at the third letter, and "at" is not at the start.

Example 2
drafts=["go", "go"], query="go" → 2

Identical drafts each count separately, and a word is a start of itself.

Example 3
drafts=["longer"], query="long" → 0

The draft is longer than the query, so it cannot be its start.

Constraints
  • 1 ≤ len(drafts) ≤ 1000
  • 1 ≤ len(drafts[i]), len(query) ≤ 20
  • All strings consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Words, Closest Apart EasyOne-Row Typing EasyDinner for Two EasyPhrases with Synonyms EasyWord from a License Plate Easy
loading Python…
Input
drafts=["c", "ca", "cat", "cab", "at"], query="cats"
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 147 tests on the server, hidden ones included.