Sanket and string problem algo?

Not able to code for sanket and strings problem even after understanding the problem
https://hack.codingblocks.com/practice/p/365/1569