Number of Segments in a String Problem
Number of Segments in a String Problem — ExecCode Easy DSA Practice
Solve the Number of Segments in a String problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a string s, return the number of segments in the string. Your task is to a segment is defined to be a contiguous sequence of non-space characters. Return the required answer exactly as shown in the examples.
Examples
Input {"s": "Hello, my name is John"}; Output 5. Input {"s": "Hello"}; Output 1
Constraints
0 <= s.length <= 300 s consists of lowercase and uppercase English letters, digits, or one of the following characters "!@#$%^&*()_+-=',.:". The only space character in s is ' '.
Practice Number of Segments in a String free on ExecCode. Browse DSA problems, topic map, and placement guides.