MEDIUMasked at 1 company

Number of Same-End Substrings

A medium-tier problem at 61% community acceptance, tagged with Array, Hash Table, String. Reported in interviews at Sprinklr and 0 others.

Founder's read

You're looking at a medium-difficulty string counting problem that shows up in Sprinklr assessments. Same-end substrings sound straightforward until you realize the naive O(n^2) check for every possible substring kills your time. The trick is recognizing that you don't need to build all substrings at all. Most candidates waste 10-15 minutes on brute force before pivoting. If this problem hits your live OA and you blank on the pattern, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
61%

Companies that ask "Number of Same-End Substrings"

If this hits your live OA

Number of Same-End Substrings is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The core insight is that same-end substrings (where first and last characters match) can be counted without iterating through every substring. Instead, you track character positions and count pairs efficiently using a hash table or prefix sum approach. The Array and Hash Table topics hint at the intended solution: store indices where each character appears, then count how many pairs you can form. Common pitfalls include trying to validate every substring's endpoints individually, or confusing the counting logic when the same character appears multiple times. Prefix Sum appears in the topic list because some candidates solve this by preprocessing character positions. Once you see that you're really just counting character occurrences and their combinations, the solution clicks. StealthCoder is your safety net if the pattern doesn't emerge during the live assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Number of Same-End Substrings recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Same-End Substrings interview FAQ

Is this problem still asked at FAANG or just Sprinklr?+

Reports show Sprinklr as the primary asker. It's lower frequency overall, so don't expect it at every major company's OA. That said, the counting and hash table pattern generalizes across string problems, so mastering it pays off broadly.

What's the trick that separates medium from hard difficulty?+

The trick is realizing you count character pairs, not substrings. If a character appears k times, you can form k(k-1)/2 same-end substrings. Most candidates miss this and try to validate each substring, which is O(n^2) or worse.

How do Hash Table and Prefix Sum both apply here?+

Hash Table stores character frequencies or positions. Prefix Sum is an alternative preprocessing step for position tracking. Depending on implementation, you might use either. The Hash Table route is more intuitive for counting occurrences.

What's the acceptance rate tell me about how tricky this actually is?+

61% acceptance is solid for medium, suggesting most people who attempt it pass. That means the problem is fair and the pattern, once understood, is implementable. You're not dealing with an edge-case monster.

If I only have 20 minutes in the OA, is this worth attempting?+

Yes, but only if you recognize the character-pairing pattern early. If you find yourself looping through substrings after 5 minutes, pivot to a counting approach or move on. It's fast once you see it, brutal if you don't.

Want the actual problem statement? View "Number of Same-End Substrings" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.