RTDS Technologies interview question

I was asked to solve a medium level leetcode question on strings.