Problem · String

Count Case-Insensitive Triplets

Learn this problem
EasyTiktok logoTiktokINTERNOA
See Tiktok hiring insights

Problem statement

Given a string text consisting of uppercase and lowercase English letters, count all triplets of consecutive characters for which the first and last characters are the same when compared case-insensitively.

Note: You are not expected to provide the most optimal solution, but a solution with time complexity no worse than O(text.length^2) will fit within the execution time limit.

Function

solution(text: String) → int

Examples

Example 1

text = "aXA"return = 1

The only triplet is "aXA". Its first and last characters are equal when compared case-insensitively, so the answer is 1.

Example 2

text = ""return = 0

An empty string has no triplet of consecutive characters, so the answer is 0.

Constraints

  • text contains only uppercase and lowercase English letters.
  • text may be empty.

More Tiktok problems

drafts saved locally
public int solution(String text) {
    // Write your code here.
}
text"aXA"
expected1
checking account