Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn = 200010;
char s[maxn];
int next[maxn][26];
int last[26];
int dp[maxn];
char ans[maxn];
int main(){
    scanf("%s",s+1);
    int n = strlen(s+1);
    for(int i = 0;i<26;i++){
        last[i] = maxn-1;
    }
    for(int i = n;i>0;i--){
        for(int j = 0;j<26;j++){
            next[i][j]  = last[j];
        }
        last[s[i]-'a'] = i;
    }
    for(int j = 0;j<26;j++){
        next[0][j]  = last[j];
    }
    memset(dp,0x3f,sizeof(dp));
    dp[maxn-1] = 0;
    for(int i = n;i>=0;i--){
        for(int j = 0;j<26;j++){
            dp[i] = min(dp[i],dp[next[i][j]]+1);
        }
    }
    int p = 0;
    int tp = 0;
    while(1){
        for(int i = 0;i<26;i++){
            if(dp[p] == dp[next[p][i]] + 1){
                ans[tp++] = i+'a';
                p = next[p][i];
                break;
            }
        }
        if(p == maxn-1) break;
    }
    ans[tp] = 0;
    printf("%s\n",ans);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:13: error: reference to 'next' is ambiguous
   17 |             next[i][j]  = last[j];
      |             ^~~~
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:5:5: note:                 'int next [200010][26]'
    5 | int next[maxn][26];
      |     ^~~~
a.cc:22:9: error: reference to 'next' is ambiguous
   22 |         next[0][j]  = last[j];
      |         ^~~~
/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:5:5: note:                 'int next [200010][26]'
    5 | int next[maxn][26];
      |     ^~~~
a.cc:28:34: error: reference to 'next' is ambiguous
   28 |             dp[i] = min(dp[i],dp[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:5:5: note:                 'int next [200010][26]'
    5 | int next[maxn][26];
      |     ^~~~
a.cc:35:28: error: reference to 'next' is ambiguous
   35 |             if(dp[p] == dp[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:5:5: note:                 'int next [200010][26]'
    5 | int next[maxn][26];
      |     ^~~~
a.cc:37:21: error: reference to 'next' is ambiguous
   37 |                 p = next[p][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:5:5: note:                 'int next [200010][26]'
    5 | int next[maxn][26];
      |     ^~~~