EarnIn interview question

Coding question on DSA and time complexity. I got a question on string manipulation.