FastPrepWord Appears Exactly N Times
Problems/Word Appears Exactly N Times

Word Appears Exactly N Times

Nutanix logoNutanix● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Nutanix intern candidate wrote this report about an on-campus interview that followed a career fair. Its first coding question is a true-or-false check on how often one word shows up in a piece of text. Only whole words count. The report adds a follow-up on running time and on making the solution faster.

The report does not say whether letter case matters, which characters the text can hold, or whether digits count as letters. It gives no limits or examples. Here we chose the following. A word is a block of English letters, and any other character, digits included, ends it. Matching is case-sensitive. The text uses letters, digits, spaces and a few punctuation marks, and has at most 5000 characters. n is from 0 to 5000. The word has 1 to 20 letters. The examples are ours.

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

You are given a string s, an integer n and a string word.

A word of s is a longest block of English letters (a to z, A to Z) standing next to each other. Every other character, including digits, spaces and punctuation, separates words. Two words are equal only if they have exactly the same letters in the same case.

Return true if word appears as a word of s exactly n times, and false otherwise. Copies of word inside a longer word do not count.

Function

appearsExactly(s: String, n: int, word: String) → boolean

Examples

Example 1

s = "the cat, the hat; THE end"n = 2word = "the"return = true

The words are the, cat, the, hat, THE and end. Exactly two of them are spelled the; THE has different letters (case matters). So the answer is true.

Example 2

s = "go,go-gone 2go"n = 2word = "go"return = false

The comma, the dash, the space and the digit 2 all separate words, so the words are go, go, gone and go. gone is a different word, but go still appears 3 times, not 2. The answer is false.

Example 3

s = "...!!"n = 0word = "x"return = true

The string has no letters, so it has no words. The word appears 0 times, which is exactly n = 0, so the answer is true.

Constraints

  • 1 <= s.length <= 5000
  • s consists of English letters, digits, spaces and the characters , . ; : ! ? - ( ).
  • 0 <= n <= 5000
  • 1 <= word.length <= 20, and word consists only of English letters.

More Nutanix Onsite Interview questions

  • Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
  • Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
  • Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 2026
  • Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
  • LRU CacheONSITE INTERVIEW · Seen Aug 2025
  • Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
  • Custom Array IteratorONSITE INTERVIEW · Seen Dec 2024
  • Collapse Runs of Repeated CharactersONSITE INTERVIEW · Seen Nov 2022
  • Anagram Words in a SentenceONSITE INTERVIEW · Seen Apr 2022
  • Sudoku SolverONSITE INTERVIEW · Seen Feb 2022

Similar questions at other companies

  • Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Convert Hexadecimal to Dotted IPv4Microsoft · ONSITE INTERVIEWMicrosoft interview questions
  • Message Latencies from CSV LogsAmazon · ONSITE INTERVIEW
  • URL / Path Segment Compression Part 1Stripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Most Cost-Effective MachineCapital One · ONSITE INTERVIEWCapital One interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
  • Molecular Weight of a Grouped FormulaAgoda · ONSITE INTERVIEWAgoda interview questions

Interview reports that mention this question

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)

Nutanix interview experiences

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public boolean appearsExactly(String s, int n, String word) {
        // Write your code here.
    }
}
Checking account…