Letter most:
For each lowercase letter count number of its occurrences in $$$s$$$, maximum of this value for all letters is the answer. All can be done in $$$O(n)$$$.
Array modification:
Assume will be the maximum. it can be proven that all operation should be done in direction of $$$x$$$ ($$$j=i+1$$$ for all operation on its left and $$$j=i-1$$$ for all operations on its right).
Now consider $$$pref_x$$$ is maximum value of $$$a_x$$$ if all operations be done in direction of right for all $$$i=1, 2, ..., x$$$.
And consider $$$suf_x$$$ is maximum value of $$$a_x$$$ if all operations be done in direction of left for all $$$i=x, x+1, ..., n$$$.
It can bee seen that:
$$$pref_x = \frac{perf_{x-1}}{2} + a_x$$$.
$$$suf_x = \frac{suf_{x+1}}{2} + a_x$$$.
And so the answer is $$$max_{i=1}^{n}(pref_i + suf_i - a_i)$$$.
All can be done in $$$O(n)$$$.
Plan for nothing:
Consider an array $$$c_1, c_2, .., c_n$$$, for all intervals like $$$[l, r]$$$ do the following operation:
$$$c_l = c_l + 1$$$.
if $$$r < n$$$, $$$c_{r+1} = c_{r+1} - 1$$$.
Then consider $$$pref_i = c_1 + c_2 + ... c_i$$$. a day is good for date if and only if $$$pref_i = 0$$$.
So the answer will be minimum $$$i$$$ that $$$pref_i = 0$$$ and if it doesn't exist answer is $$$-1$$$.