Sanket and Strings

https://ide.codingblocks.com/s/296168 I’m using this approach to solve this question, but output is not correct, So can you please check my code and let me know where i’m wrong. Thanks.