Language: C++

#include <bits/stdc++.h>
using namespace std;
#define MAX 200007
#define INF "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
typedef long long ll;

string s;
// int f[MAX][26];
int next[MAX][26];
int n;
string res[MAX];

string dfs(int l){
	if(l==(n-1)){
		if(s[l]=='a')return "b";
		else {
			char c=s[l];
			c--;
			return string(1,c);
		}
	}
	if(res[l]!=INF)return res[l];
	string tmp=INF;
	for(int i=0;i<26;i++){
		string p;
		if(next[l][i]+1 < n)p = string(1,i+'a')+dfs(next[l][i]+1);
		else if (next[l][i] == (n-1))p = string(1,i+'a')+"a";
		else p=string(1,i+'a');
		if(p.size() < tmp.size() || (p.size() == tmp.size() &&  p < tmp))tmp=p;
	}
	res[l]=tmp;
	return tmp;
}
int main(){
	cin >> s;
	n=s.size();
	fill(res,res+MAX,INF);
	// for(int i=0;i<s.size();i++)f[i][s[i]-'a']++;
	for(int i=0;i<26;i++){
		int last=n;
		for(int j=n-1;j>=0;j--){
			if(s[j]-'a' == i)last = j;
			next[j][i]=last;
		}
	}
/*	for(int i=0;i<26;i++){
		for(int j=0;j<n;j++) cout << next[j][i] << " ";
		cout << endl;
	}
*/
	cout << dfs(0) << endl;
}

Compiler output:
a.cc: In function 'std::string dfs(int)':
a.cc:26:20: error: reference to 'next' is ambiguous
   26 |                 if(next[l][i]+1 < n)p = string(1,i+'a')+dfs(next[l][i]+1);
      |                    ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:5: note:                 'int next [200007][26]'
    9 | int next[MAX][26];
      |     ^~~~
a.cc:26:61: error: reference to 'next' is ambiguous
   26 |                 if(next[l][i]+1 < n)p = string(1,i+'a')+dfs(next[l][i]+1);
      |                                                             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:5: note:                 'int next [200007][26]'
    9 | int next[MAX][26];
      |     ^~~~
a.cc:27:26: error: reference to 'next' is ambiguous
   27 |                 else if (next[l][i] == (n-1))p = string(1,i+'a')+"a";
      |                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:5: note:                 'int next [200007][26]'
    9 | int next[MAX][26];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:43:25: error: reference to 'next' is ambiguous
   43 |                         next[j][i]=last;
      |                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:9:5: note:                 'int next [200007][26]'
    9 | int next[MAX][26];
      |     ^~~~