FastPrepCount Valid Space-Delimited Words
Problems/Count Valid Space-Delimited Words

Count Valid Space-Delimited Words

Visa logoVisa● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report asks to split text on spaces and drop tokens that contain digits or symbols other than comma, period, question mark, and exclamation mark. We fixed how repeated spaces and the position of punctuation work. Our version is about 88% the same as the reported question.

Split text on one or more ASCII space characters and ignore empty pieces. Return the number of valid tokens.

A valid token contains one or more ASCII letters and may optionally end with exactly one of ,, ., ?, or !. Digits are never allowed, and punctuation may not appear anywhere except the final character.

Function

countValidWords(text: String) → int

Examples

Example 1

text = "hello world! 123 no-way ok?"return = 3

hello, world!, and ok? are valid; the numeric and hyphenated tokens are not.

Example 2

text = "  A, b. wow!! fine?  "return = 3

Repeated spaces are ignored. wow!! is invalid because it has more than one punctuation mark.

Constraints

  • 0 <= text.length <= 100000.
  • text contains printable ASCII characters.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
  • Minimum Values with Even Powers of TwoOA · Seen Sep 2026

Similar questions at other companies

  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
  • Validate Email AddressAccenture · OAAccenture interview questions
  • Is This Date a Weekend?Salesforce · OASalesforce interview questions
  • FIX Message ReconciliationVirtu Financial · OAVirtu Financial interview questions
  • IPv4 Address ClassificationRippling · OARippling interview questions
  • Generate Table of ContentsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Highest-Ranked University by CountryAgoda · OAAgoda interview questions
  • Counterfeit CurrencyBox · OABox interview questions
  • Convert Snake Case Variables to Camel CaseRamp · OARamp interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int countValidWords(String text) {
        // Write your code here.
    }
}
Checking account…