Lexicographical string problem

can u see where i am geeting wrong.
and also solution for this problem is given in c++.

@Sumant123,
Can you please share your code so that I can review?