Count Length-Three Windows with Matching Ends
Updated
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.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
Similar questions at other companies
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Get Special Substring (MTS)Salesforce · OASalesforce interview questions
- Longest Cipher (Intuit India)Intuit · OAIntuit interview questions
- Find RepetitionsPure Storage · OAPure Storage interview questions
- Perfect SubstringAXQ Capital · OA
- Incident MonitorStripe · OAStripe interview questions
- Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
- Same Substring Within BudgetJP Morgan Chase · OAJP Morgan Chase interview questions
- Longest Distinct StringSuperhuman · OASuperhuman interview questions
- K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions