Morgan Stanley interview question

Leetcode question on string manipulation