Tap here to switch tabs
Problem
Submissions

Problem: Number of Valid Words in a Sentence

med
30 min
Try to solve the Number of Valid Words in a Sentence problem.

Statement

A sentence consists of tokens separated by one or more spaces. A token is defined as a contiguous sequence of non-space characters.

A token is considered a valid word if it satisfies all of the following conditions:

  • It does not contain any digits, consisting only of lowercase English letters, hyphens '-', and punctuation marks ('!', '.', and ',').

  • It contains at most 11 hyphen '-'. If present, the hyphen must be surrounded by lowercase English letters on both sides.

  • It contains at most 11 punctuation mark. If present, the punctuation mark must be at the very end of the token.

Given a string sentence, return the number of valid words in sentence.

Constraints:

  • 1≤1 \leq sentence.length ≤1000\leq 1000

  • sentence only contains lowercase English letters, digits, ' ', '-', '!', '.', and ','.

  • There will be at least 11 token.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Valid Words in a Sentence

med
30 min
Try to solve the Number of Valid Words in a Sentence problem.

Statement

A sentence consists of tokens separated by one or more spaces. A token is defined as a contiguous sequence of non-space characters.

A token is considered a valid word if it satisfies all of the following conditions:

  • It does not contain any digits, consisting only of lowercase English letters, hyphens '-', and punctuation marks ('!', '.', and ',').

  • It contains at most 11 hyphen '-'. If present, the hyphen must be surrounded by lowercase English letters on both sides.

  • It contains at most 11 punctuation mark. If present, the punctuation mark must be at the very end of the token.

Given a string sentence, return the number of valid words in sentence.

Constraints:

  • 1≤1 \leq sentence.length ≤1000\leq 1000

  • sentence only contains lowercase English letters, digits, ' ', '-', '!', '.', and ','.

  • There will be at least 11 token.