EarnIn Interview Question

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