Language: C++

//In The Name of Beauty
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef vector<ll> vll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
ll const MAXN = 1e5 + 8;
ll const INF  = 1e12 + 8;
ll const delta = 1000000007;
ll last[30];
int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    ll ans = s.size() - 1;
    for(ll i = 0;i < 30;i++)last[i] = -1;
    for(ll i = 0;i < 30;i++){
        ll temp = 0;
        for(ll j = 0;j < s.size();j++){
            if(s[j] != 'a' + i)continue;
            if(last[i] == -1)temp = max(temp,j);
            else temp = max(temp,j - last[i] - 1);
            last[i] = j;
        }
        if(last[i] == -1)continue;
        temp = max(temp,s.size() - last[i] - 1);
        ans = min(ans,temp);
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


Compiler output:
a.cc:13:22: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.000000000008e+12' to '2147483647' [-Woverflow]
   13 | ll const INF  = 1e12 + 8;
      |                 ~~~~~^~~
a.cc: In function 'int main()':
a.cc:34:19: error: no matching function for call to 'max(ll&, std::__cxx11::basic_string<char>::size_type)'
   34 |         temp = max(temp,s.size() - last[i] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:34:19: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'})
   34 |         temp = max(temp,s.size() - last[i] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:34:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   34 |         temp = max(temp,s.size() - last[i] - 1);
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~