We iterate from a full-string scan to a half-string walk by noticing the mirror-index symmetry between `s[i]` and `s[n - i - 1]`. A handy trick for any "compare from both ends" problem.
We iterate from a full-string scan to a half-string walk by noticing the mirror-index symmetry between `s[i]` and `s[n - i - 1]`. A handy trick for any "compare from both ends" problem.
You are given a string s of length n consisting of lowercase English letters.
Return the smallest index i such that s[i] == s[n - i - 1].
If no such index exists, return -1.