Language: C++

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=2e5+10;

int n;
char a[maxn];
int next[maxn][26];
int dp[maxn];
int last;

void dfs(int p)
{
	if (p>n) 
	{
		printf("a\n");
		return;
	}
	for(int i=0;i<26;i++)
	{
		if (next[p][i]==-1)
		{
			printf("%c",i+'a');
			return;
		}
		if (dp[p]==dp[next[p][i]+1]+1)
		{
			printf("%c",i+'a');
			dfs(next[p][i]+1);
			return;
		}
	}
}

int main() 
{
	scanf("%s",a+1);
	n=strlen(a+1);
	for(int i=0;i<26;i++)
	{
		last=-1;
		for(int j=n;j>=1;j--)
		{
			if (a[j]-'a'==i) last=j;
			next[j][i]=last;
		}
	}
	
	dp[n+1]=1;
	for(int i=n;i>=1;i--)
	{
		dp[i]=n+1;
		for(int j=0;j<26;j++)
		{
			if (next[i][j]==-1) 
			{
				dp[i]=1;
				break;
			}
			dp[i]=min(dp[i],dp[next[i][j]+1]+1);
		}
	}
	
	dfs(1);
	printf("\n");
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:22:21: error: reference to 'next' is ambiguous
   22 |                 if (next[p][i]==-1)
      |                     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:3:
/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 [200010][26]'
    9 | int next[maxn][26];
      |     ^~~~
a.cc:27:31: error: reference to 'next' is ambiguous
   27 |                 if (dp[p]==dp[next[p][i]+1]+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 [200010][26]'
    9 | int next[maxn][26];
      |     ^~~~
a.cc:30:29: error: reference to 'next' is ambiguous
   30 |                         dfs(next[p][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 [200010][26]'
    9 | int next[maxn][26];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:46:25: error: reference to 'next' is ambiguous
   46 |                         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 [200010][26]'
    9 | int next[maxn][26];
      |     ^~~~
a.cc:56:29: error: reference to 'next' is ambiguous
   56 |                         if (next[i][j]==-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 [200010][26]'
    9 | int next[maxn][26];
      |     ^~~~
a.cc:61:44: error: reference to 'next' is ambiguous
   61 |                         dp[i]=min(dp[i],dp[next[i][j]+1]+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 [200010][26]'
    9 | int next[maxn][26];
      |     ^~~~