0 out of 464 challenges solved
Write a Python function `number_of_substrings(s: str) -> int` that calculates the number of non-empty substrings of a given string `s`. A substring is defined as a contiguous sequence of characters within a string. For a string of length `n`, the total number of non-empty substrings can be calculated using the formula: \[ \text{Number of substrings} = \frac{n \times (n + 1)}{2} \] #### Example Usage ```python [main.nopy] print(number_of_substrings("abc")) # Output: 6 print(number_of_substrings("abcd")) # Output: 10 print(number_of_substrings("a")) # Output: 1 ``` #### Constraints - The input string will have a length between 1 and 10,000. - The function should run efficiently for large input sizes.
def number_of_substrings(s: str) -> int: """ Calculate the number of non-empty substrings of the given string. Args: s (str): The input string. Returns: int: The number of non-empty substrings. """ # Placeholder for the solution pass