Morgan Stanley Interview Question

Leetcode question on string manipulation