KPIT Technologies interview question

Coding question on strings in hacckerank