Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int next[26][210000];
int best[210000];
int bestl[210000];
int main(){
	string a;
	cin >> a;
	int n = a.size();
	for(int c = 0; c < 26; c++){
		next[c][n] = n;
		for(int i = n-1; i >= 0; i--){
			next[c][i] = next[c][i+1];
			if(a[i] - 'a' == c) next[c][i] = i;
		}
	}
	best[n+1] = 0;
	for(int i = n; i >= 0; i--){
		best[i] = 110000000;
		bestl[i] = -1;
		for(int c = 0; c < 26; c++){
			if(best[next[c][i] + 1] + 1 < best[i]){
				bestl[i] = c;
				best[i] = best[next[c][i] + 1] + 1;
			}
		}
	}
	int r = 0;
	while(r < n){
		if(bestl[r] == -1){
			r++;
		} else {
			cout << (char)(bestl[r] + 'a');
			r = next[bestl[r]][r] + 1;
		}
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:17: error: reference to 'next' is ambiguous
   12 |                 next[c][n] = n;
      |                 ^~~~
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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~
a.cc:14:25: error: reference to 'next' is ambiguous
   14 |                         next[c][i] = next[c][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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~
a.cc:14:38: error: reference to 'next' is ambiguous
   14 |                         next[c][i] = next[c][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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~
a.cc:15:45: error: reference to 'next' is ambiguous
   15 |                         if(a[i] - 'a' == c) next[c][i] = i;
      |                                             ^~~~
/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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~
a.cc:23:33: error: reference to 'next' is ambiguous
   23 |                         if(best[next[c][i] + 1] + 1 < best[i]){
      |                                 ^~~~
/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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~
a.cc:25:48: error: reference to 'next' is ambiguous
   25 |                                 best[i] = best[next[c][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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~
a.cc:35:29: error: reference to 'next' is ambiguous
   35 |                         r = next[bestl[r]][r] + 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:4:5: note:                 'int next [26][210000]'
    4 | int next[26][210000];
      |     ^~~~