Count Substrings Starting and Ending with Given Character - Practice Coding | SlaveCode
0
0123456789
0
0123456789
:
0
0123456789
0
0123456789
3084. Count Substrings Starting and Ending with Given Character
Medium
30 Points
Math
String
Counting
You are given a string s and a character c. Return the total number of substrings of s that start and end with c.
Examples
Example 1
Input: s = "abada", c = "a"
Output: 6
Explanation: Substrings starting and ending with "a" are: " a bada" , " aba da" , " abada " , "ab a da" , "ab ada " , "abad a " .
Example 2
Input: s = "zzz", c = "z"
Output: 6
Explanation: There are a total of 6 substrings in s and all start and end with "z" .
Constraints
1 <= s.length <= 105
s and c consist only of lowercase English letters.
3084. Count Substrings Starting and Ending with Given Character
Medium
30 Points
Math
String
Counting
You are given a string s and a character c. Return the total number of substrings of s that start and end with c.
Examples
Example 1
Input: s = "abada", c = "a"
Output: 6
Explanation: Substrings starting and ending with "a" are: " a bada" , " aba da" , " abada " , "ab a da" , "ab ada " , "abad a " .
Example 2
Input: s = "zzz", c = "z"
Output: 6
Explanation: There are a total of 6 substrings in s and all start and end with "z" .
Constraints
1 <= s.length <= 105
s and c consist only of lowercase English letters.