FastPrepCount Case-Insensitive Triplets
Problems/Count Case-Insensitive Triplets

Count Case-Insensitive Triplets

TikTok logoTikTok● EasyINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The screenshot cuts off the empty-string example's output. The judged core task matches the visible source at about 99%.

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

  • Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
  • Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
All TikTok interview questionsSee TikTok hiring insights
Saved
class Solution {
    public int solution(String text) {
        // Write your code here.
    }

}
Checking account…