All practice tasks

Coding (Algo)

Count Matching Name Prefixes

Prefix matching · Easy

A name-filter preview receives a list of lowercase alphanumeric identifiers and a single search prefix. It needs the number of matching entries. Duplicate identifiers represent separate records and must not be collapsed.

Return how many entries in words begin with prefix, counting duplicates as separate matching records.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

A JSON object { "words": string[], "prefix": string }.

Fields

  • words contains lowercase ASCII letters a-z and digits 0-9; each entry may be empty.
  • prefix uses the same alphabet and may be empty.

Output

Return value

  • Return an integer count, not the matching words.
  • An empty prefix matches every entry, including empty words.
  • This is one prefix query; building a trie is optional and earns no extra credit.

Constraints

  • 0 <= words.length <= 100000; total word characters <= 1000000; prefix.length <= 1000.
  • Digits are explicitly allowed because the original published test data already uses identifiers such as app10.

Examples

Example 1

{
  "prefix": "app",
  "words": [
    "app10",
    "api3",
    "app10",
    "cache"
  ]
}

Returns

2

Both app10 records count.

Example 2

{
  "prefix": "",
  "words": [
    "",
    "a"
  ]
}

Returns

2

Every entry has an empty prefix.

Required complexity

O(total word characters + prefix.length) time or better; constant working space is possible

What this task practices

Count Matching Name Prefixes is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.