Substrings with similar first and last characters
Basic Accuracy: 65.99% Submissions: 1377 Points: 1

Given string s, the task is to find the count of all substrings which have the same character at the beginning and end.

Example 1:

Input: s = "abcab"
Output: 7
Explanation: a, abca, b, bcab, 
c, a and b

Example 2:

Input: s = "aba"
Output: 4
Explanation: a, b, a and aba

User Task:
Your task is to complete the function countSubstringWithEqualEnds() which takes a single string as input and returns the count. You do not need to take any input or print anything.

Expected Time Complexity: O(|str|)
Expected Auxiliary Space: O(constant)

1 <= |s| <= 104

s contains lower case english alphabets

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Substrings with similar first and last characters

Output Window