FastPrepCount How Often a Word Appears in a Paragraph
Problems/Count How Often a Word Appears in a Paragraph

Count How Often a Word Appears in a Paragraph

Capital One logoCapital One● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2017 Capital One report from a Java software engineer candidate describes a phone screen question about counting how often a chosen word shows up in a block of text. A HashMap question and a take-home exercise were part of the same process.

The report does not say how words are separated or whether case matters. Here a word is a run of English letters, so punctuation, hyphens and digits end it, matching ignores case, and only whole words count. The paragraph can be up to 10^5 characters. These are our choices.

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

Treat paragraph as a sequence of words, where a word is a maximal run of English letters. Spaces, punctuation, hyphens and digits all separate words.

Count how many of those words are equal to word, ignoring upper and lower case. A word only counts when the whole word matches, not when word appears inside a longer word.

Function

countWord(paragraph: String, word: String) → int

Examples

Example 1

paragraph = "The cat sat. The cat, the CAT!"word = "cat"return = 3

Case does not matter and punctuation is not part of a word, so cat, cat, and CAT! each count: 3.

Example 2

paragraph = "category cats scatter"word = "cat"return = 0

Each of these words only contains cat inside it. A whole word has to match, so none of them counts and the answer is 0.

Example 3

paragraph = "go-goal 7go"word = "go"return = 2

A hyphen or a digit ends a word. go-goal holds go and goal, and 7go holds the word go after the digit, so go appears twice; goal does not match.

Constraints

  • 1 <= paragraph.length <= 10^5
  • paragraph uses only English letters, digits, spaces and .,;:!?-.
  • word has between 1 and 20 English letters.

More Capital One interview questions

  • Count Records Present in A but Not BPHONE SCREEN · Seen Oct 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Maximum Subarray SumPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2025
  • Ten-Pin Bowling Frame ScoresPHONE SCREEN · Seen Nov 2023
  • Min StackPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2023
  • Invert a Binary TreePHONE SCREEN · Seen Dec 2020
  • In-Memory File System With Directory SizesPHONE SCREEN · ONSITE INTERVIEW
  • Pick the K Nearest Grid Points to (0, 0)PHONE SCREEN · ONSITE INTERVIEW
  • The Nth Number in the Fibonacci SequencePHONE SCREEN · ONSITE INTERVIEW
  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • First Letter to Appear TwiceCisco · PHONE SCREENCisco interview questions
  • Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Known Words Matching Phone DigitsLinkedIn · PHONE SCREENLinkedIn interview questions
  • First Non-Repeated CharacterDell Technologies · PHONE SCREENDell Technologies interview questions
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions

Capital One interview 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
  • Capital One TDP Agentic Power Day: 25 Experiences (Part 1 of 2)
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int countWord(String paragraph, String word) {
        // Write your code here.
    }
}
Checking account…