Count Case-Insensitive Triplets
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) → intExamples
Example 1
text = "aXA"return = 1The only triplet is "aXA". Its first and last characters are equal when compared case-insensitively, so the answer is 1.
Example 2
text = ""return = 0An empty string has no triplet of consecutive characters, so the answer is 0.
Constraints
textcontains only uppercase and lowercase English letters.textmay be empty.