Count Length-Three Windows with Matching Ends
Problem statement
You are given a string text.
Count the contiguous substrings of length exactly 3 whose first and last characters are equal. Windows may overlap. Return the count.
Function
countMatchingEndpointTriples(text: String) → intExamples
Example 1
text = "abcxccc"return = 2The matching windows are cxc and ccc.
Example 2
text = "aba"return = 1The only length-three window begins and ends with a.
Example 3
text = "ab"return = 0A string shorter than three characters contains no eligible window.
Constraints
0 <= text.length <= 2 * 105textcontains printable ASCII characters.