Count Magical Adjacent Substring Triplets
Updated
Problem statement
Two nonempty strings form a magical pair when their sets of distinct lowercase letters are equal.
Return the number of triplets (i,j,k) with i <= j < k for which adjacent substrings text[i..j] and text[j+1..k] form a magical pair.
Function
countMagicalTriplets(text: String) → longExamples
Example 1
text = "aa"return = 1The two one-letter substrings have the same set.
Example 2
text = "ababa"return = 4Several adjacent pairs share {a,b}, with additional one-letter matches.
Example 3
text = "abc"return = 0No adjacent pair has equal distinct-character sets.
Constraints
0 <= text.length <= 5000.- The string contains lowercase English letters.
- The answer fits in a signed 64-bit integer.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Password Clues and the Next CommandOpenAI · OAOpenAI interview questions
- Spelling Bee Word FilterBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Longest Substring with Even OccurrencesDeloitte · OADeloitte interview questions
- Palindrome-Rearrangeable PairsExpedia · OAExpedia interview questions
- Palindrome PermutationRippling · OARippling interview questions
- Repeated DNA SequencesNVIDIA · PHONE SCREENNVIDIA interview questions
- Numeric Wildcard Dictionary MatchingHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Minimum Window SubstringAmazon · PHONE SCREEN · ONSITE INTERVIEW