Rakuten Interview Question

Some string manipulation which I was trying to understand.