Language: C++

/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2017-08-20	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
int len;
int f[200050],next[200050];
char str[200050];
set<int> ch[26];
void laboras()
{
	int st=len;
	set<int>::iterator it;
	for(int i=0;i<=len;i++) f[i]=2147483647;
	for(int i=len-1;0<=i;i--)
	{
		for(int j=0;j<26;j++)
		{
			it=ch[j].lower_bound(i+1);
			if(it==ch[j].end())
			{
				f[i]=2;
				next[i]=len;
			}
			else if(f[*it]+1<f[i])
			{
				f[i]=f[*it]+1;
				next[i]=*it;
			}
		}
	}
	for(int i=0;i<26;i++)
	{
		it=ch[i].lower_bound(0);
		if(it==ch[i].end())
		{
			putchar('a'+i);
			st=len;
			break;
		}
		if(f[*it]<f[st])
			st=*it;
	}
	while(st<len)
	{
		putchar(str[st]);
		if(next[st]==len)
		{
			for(int i=0;i<26;i++)
			{
				if(ch[i].lower_bound(st+1)==ch[i].end())
				{
					putchar('a'+i);
					break;
				}
			}
			break;
		}
		st=next[st];
	}
	return;
}
int main()
{
	scanf("%s",str);
	len=strlen(str);
	for(int i=0;i<len;i++)
		ch[str[i]-'a'].insert(i);
	laboras();
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Compiler output:
a.cc: In function 'void laboras()':
a.cc:34:33: error: reference to 'next' is ambiguous
   34 |                                 next[i]=len;
      |                                 ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:8:
/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:18:15: note:                 'int next [200050]'
   18 | int f[200050],next[200050];
      |               ^~~~
a.cc:39:33: error: reference to 'next' is ambiguous
   39 |                                 next[i]=*it;
      |                                 ^~~~
/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:18:15: note:                 'int next [200050]'
   18 | int f[200050],next[200050];
      |               ^~~~
a.cc:58:20: error: reference to 'next' is ambiguous
   58 |                 if(next[st]==len)
      |                    ^~~~
/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:18:15: note:                 'int next [200050]'
   18 | int f[200050],next[200050];
      |               ^~~~
a.cc:70:20: error: reference to 'next' is ambiguous
   70 |                 st=next[st];
      |                    ^~~~
/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:18:15: note:                 'int next [200050]'
   18 | int f[200050],next[200050];
      |               ^~~~