FastPrepTriplets With Unique Chars

Triplets With Unique Chars

ZipRecruiter logoZipRecruiter● EasyINTERNOA
Learn

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) → int

Examples

Example 1

text = "abcdaaae"return = 3

The valid triplets are abc, bcd, and cda, so the answer is 3.

Example 2

text = "abacaba"return = 2

The valid triplets are bac and cab, so the answer is 2.

Constraints

  • 1 <= text.length <= 1000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int tripletsWithUniqueChars(String text) {
  // write your code here
}
text"abcdaaae"
expected3
Checking account…