Introduction

Greetings! Today, you will dive into handling and manipulating strings in Kotlin, a fundamental skill across many areas of programming. Specifically, we'll explore how to identify consecutive groups of identical characters in a string. Eager to enhance your Kotlin skills? Let's get started!

Task Statement

In this lesson, your objective is to write a Kotlin function that accepts a string as input and identifies all consecutive groups of identical characters within it. A group is defined as a segment of text wherein the same character is repeated consecutively.

Your function should return a List of strings. Each string will consist of the repeating character and the length of its repetition, joined by a colon (:). For example, if the input string is "aaabbcccaae", your function should output: "a:3", "b:2", "c:3", "a:2", "e:1".

Remember, while processing the input string, we are interested only in alphanumeric characters (i.e., letters and digits), without differentiating the case. Non-alphanumeric characters should be ignored when forming these groups.

Ready to learn how to accomplish this task with Kotlin? Let's move forward!

Step 1: Initialization

When solving any problem, it's crucial to start by establishing our scope with some preliminary steps. First, we will initialize an empty MutableList to store our results. We will also declare two variables, currentGroupChar and , to help us monitor the character of the current group and its consecutive sequence length.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal