FunctionRacerProblemsRace

Number of Segments in a String

EasyStringsPython, JavaScript, TypeScript, Java, C++

A segment is a run of consecutive characters that are not spaces. Return how many segments s has. The string may be empty or have spaces at the start, the end, or several in a row.

Example 1

s "Hello, my name is John"
returns 5

Five segments, because punctuation counts as part of a segment.

Example 2

s " "
returns 0

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems