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

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Streams & I/O problems