Skip to content

Practice Count Substrings Starting and Ending with Given Character

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3084
LeetCode Problem

Count Substrings Starting and Ending with Given Character

Problem Statement

You are given a string s and a character c. Return the total number of substrings of s that start and end with c.

Source: Count Substrings Starting and Ending with Given Character on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "abada", c = "a"
Output
6

# Example 2

Input
s = "zzz", c = "z"
Output
6

Constraints

1 <= s.length <= 10^5
s and c consist only of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Count Substrings Starting and Ending with Given Character.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.