Source Code
#include <bits/stdc++.h>

using namespace std;

int main() {
    //freopen("cubes.in", "r", stdin);
    //freopen ("output.txt","w",stdout);
    int t = 1;
    // cin >> t;
    for (int j = 0; j < t; j++) {
        string s;
        cin >> s;
        char ch = 'a';
        int ans = 1e9;
        for(char c = 'a'; c <= 'z'; c++) {
            int x = 0;
            for(char l : s) {
                x += abs(l - c);
            }
            ans = min(ans, x);
        }
        cout << ans;
    }
    return 0;
}
Copy
Palindrome Substrings Fattah
GNU G++17
9 ms
840 KB
Accepted