Tinkoff Digital interview question

String task like easy from leetcode.