Practice

Count Words in a Sentence

MEDIUMString Processing7 marks

Read a sentence and output its number of words.

Words are groups of non-space characters. The sentence may contain leading, trailing, or repeated spaces.

Input: One string. Output: The number of words.

Example:

Input:  pseudocode is useful
Output: 3
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Three words
Inputs: pseudocode is useful
Expected: 3
Test 2: One word
Inputs: Hello
Expected: 1