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

Open every published interview problem, solution, scene, and memory room free, with no account.

More Streams & I/O problems