Tinkoff Digital Interview Question

String task like easy from leetcode.