Easy · Streams & I/O

Count words in file

Given the path of a text file, return the number of words in it, where a word is a maximal run of non-whitespace characters.

Examples

Example 1

{
  "text": "hello world foo"
}

Output: 3

Example 2

{
  "text": "one two three four"
}

Output: 4

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Streams & I/O problems