Triplets With Unique Chars
Problem statement
Given a string text, count its contiguous substrings of length three whose three characters are all different.
Return the number of such triplets. Overlapping triplets are counted separately.
Function
tripletsWithUniqueChars(text: String) → intExamples
Example 1
text = "abcdaaae"return = 3The valid triplets are abc, bcd, and cda, so the answer is 3.
Example 2
text = "abacaba"return = 2The valid triplets are bac and cab, so the answer is 2.
Constraints
1 <= text.length <= 1000