Bloomberg interview question

Q. Leetcode Medium problem. (on strings)