Finding the lexicographically smallest palindrome of the same length that is lexicographically greater than or equal to given string s
Let's assume the length is even for now. Split the word up into two equal parts, $w = lr$. Let $l^R$ be the reverse of $l$.
If $l^R = r$, we are done immediately. Otherwise, if $r &lt; l^{R}$ we can set $r$ equal to $l^R$. The more involved case is when $l^R &lt; r$. In that case we will need to increment $l$ by one (view the lowercase English words as a base-26 number - this exactly matches lexicographic order), after which we can set $r$ equal to the reversed left hand side and we'll still be lexicographically bigger.
Now if our original word was odd in length we apply the exact same process, except when we shouldn't increment $l$ by one but start the increment one more to the right: at the middle element instead.
Some example code in C:
void increment_base26(char* s, int len) {
    int i = len - 1;
    while (i &gt;= 0) {
        if (s[i] == 'z') s[i] = 'a'; // Wrap around and carry.
        else { s[i] += 1; break; }
        i -= 1;
    }
}

void reverse(char *s, int len) {
    for (int i = 0; i &lt; len - 1 - i; ++i) {
        char t = s[i];
        s[i] = s[len - 1 - i];
        s[len - 1 - i] = t;
    }
}

void next_lexicographic_palindrome(char* s) {
    int len = strlen(s);
    int half = len / 2; // Rounds down.
    int half_plus_mid = half + (len % 2);
    reverse(s, half);                                // Compute l^R.
    int cmp = strncmp(s, s + half_plus_mid, half);   // Compare l^R and r.
    if (cmp &gt; 0) memcpy(s + half_plus_mid, s, half); // l^R &gt; r, can just copy over l^R.
    reverse(s, half);                                // Undo l^R -&gt; l.
    if (cmp &gt;= 0) { return; }                        // Simple cases l^R &gt;= handled.
    increment_base26(s, half_plus_mid);              // Increment left + mid.
    reverse(s, half);                                // Copy over the new l^R to r.
    memcpy(s + half_plus_mid, s, half);
    reverse(s, half);
}