FastPrepCount Words with Each Prefix
Problems/Count Words with Each Prefix

Count Words with Each Prefix

Capital One logoCapital One● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Capital One backend intern online assessment in Toronto had a medium question about matching the start of strings. The author thought a trie was the right tool and ran out of time while building one.

The report does not give the exact task, the input, the output, or any limits. Here, you get a word list and a query list, and for each query you count the words that begin with it. A word equal to the query counts, and a repeated word counts once per copy. The limits are our choice.

Our version is about 50% the same as the reported question.

You are given a list of strings words and a list of strings queries. For each query, count how many strings in words start with that query. Return an array answer where answer[j] is the count for queries[j].

  • A word starts with a query when the first letters of the word are exactly the query. A word that is equal to the query counts.
  • If the same word appears more than once in words, every copy counts.
  • A match in the middle or at the end of a word does not count.

Function

countWordsWithPrefix(words: String[], queries: String[]) → int[]

Examples

Example 1

words = ["apple","app","apply","bat","app"]queries = ["app","ap","apple","b","c"]return = [4,4,1,1,0]

Four words start with "app": "apple", both copies of "app", and "apply". A word that equals the query counts, and each copy counts. The same four words start with "ap". Only "apple" starts with "apple". Only "bat" starts with "b", and no word starts with "c".

Example 2

words = ["car","card","care","cart"]queries = ["cards","car","card"]return = [0,4,1]

No word starts with "cards". The word "card" is the start of the query, but that is the other way around, so it does not count. All four words start with "car", and only "card" starts with "card".

Example 3

words = ["a"]queries = ["a","aa"]return = [1,0]

The single word "a" starts with "a". It is shorter than "aa", so it cannot start with it.

Constraints

  • 1 <= words.length <= 3000
  • 1 <= queries.length <= 1000
  • 1 <= words[i].length, queries[j].length <= 20
  • words[i] and queries[j] contain only lowercase English letters.

More Capital One Online Assessment questions

  • Branch with the Most FilesOA · Seen Nov 2026
  • Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
  • Earn the Most 🐝OA · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
  • Arithmetic Triplets After QueriesOA · Seen Oct 2026
  • Count One-Swap Number PairsOA · Seen Oct 2026
  • Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
  • Sort Adjacent PairsOA · Seen Oct 2026
  • Bouncing Diagonal WeightsOA · Seen Oct 2026

Similar questions at other companies

  • Max DistanceGoogle · OAGoogle interview questions
  • Suggested ProductsSquarepoint Capital · OASquarepoint Capital interview questions
  • Find Length of Longest Common PrefixUber · OAUber interview questions
  • The Huffman Decoder 🌼Wolverine Trading · OAWolverine Trading interview questions
  • Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
  • Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Implement a TrieMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Search Suggestions with a Prefix TreeCitadel · ONSITE INTERVIEWCitadel interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int[] countWordsWithPrefix(String[] words, String[] queries) {
        // Write your code here.
    }
}
Checking account…