Rakuten interview question

Some string manipulation which I was trying to understand.