A submarine's sonar console prints the entire return signal from one sweep as a single line of text. Whenever the sonar detects nothing, the console prints the space character ' ' -- possibly many consecutive spaces if the silence lasts a while. Whenever the sonar detects part of an object, it prints some other printable character (a letter, digit, or a punctuation symbol used by the console's diagnostic firmware; never a space). A "pulse" is a maximal run of consecutive non-space characters in the printed line.
Given the printed line, which may be empty, may consist only of spaces, and may have leading or trailing spaces, determine how many pulses it contains.
A single line containing the string s. The line may be empty.
A single integer: the number of pulses in s.
Example 1
Input
blip blip echo
Expected
3
Explanation
The line contains three maximal runs of non-space characters -- "blip", "blip", and "echo" -- separated by runs of one or more spaces, so the pulse count is 3.
Example 2
Input
Expected
0
Explanation
The entire line consists only of space characters, so there are no maximal runs of non-space characters and the pulse count is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →