Comments

You are comparing the first and the last character of the string instead of comparing the complete string with its reverse.

Consider the string "acba". Take n to be any even number. Now, your code will output "acba", even though "abcaacba" is lexicographically smaller.

To correct this, check for reverseStr<str instead.

-15

UP