Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
string a;
vector<vector<int> > ne(a.size() + 1);
vector<int> dp(a.size() + 2, 100000000);
vector<char> prev(a.size() + 2, 'a');
vector<int> previ(a.size() + 2, 0);
int dfs(int i) {
	if (i == a.size() + 1) {
		return 0;
	}
	for (int j = 0; j < 26; j++) {
			if (dp[ne[i][j] + 1] > dp[i] + 1) {
				dp[ne[i][j] + 1] = dp[i] + 1;
				prev[ne[i][j] + 1] = 'a' + j;
				previ[ne[i][j] + 1] = i;
				dfs(ne[i][j] + 1);
			}
	}
	
}
signed main() {
	
	cin >> a;
	int first[26];
	int cnt[26];
	int nz = 0;
	ne.resize(a.size() + 1);
	dp.resize(a.size() + 2, 100000000);
	prev.resize(a.size() + 2, 'a');
	previ.resize(a.size() + 2, 0);

	for (int i = 0; i < a.size() + 1; i++) {
		ne[i].resize(26);
	}
	for (int i = 0; i < 26; i++) {
		ne[a.size()][i] = a.size();
	}
	for (int i = a.size() - 1; i >= 0 ; i--) {
		ne[i] = ne[i + 1];
		ne[i][(int)(a[i] - 'a')] = i;
	}
	dp[0] = 0;
	dfs(0);
	int k = a.size() + 1;
	string res;
	/*
	for (int i = 0; i <= a.size(); i++) {
		cerr << dp[i] << " ";
	}
	cerr << endl;
	for (int i = 0; i <= a.size(); i++) {
		cerr << prev[i] << " ";
	}
	cerr << endl;
	*/
	while (k > 0) {
		res += prev[k];
		k = previ[k];
	}
	for (int i = 0; i < res.size() / 2; i++) {
		swap(res[i], res[res.size() - 1 - i]);
	}
	cout << res << endl;
	return 0;
}

Compiler output:
a.cc: In function 'long long int dfs(long long int)':
a.cc:16:33: error: reference to 'prev' is ambiguous
   16 |                                 prev[ne[i][j] + 1] = 'a' + 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:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:7:14: note:                 'std::vector<char> prev'
    7 | vector<char> prev(a.size() + 2, 'a');
      |              ^~~~
a.cc: In function 'int main()':
a.cc:31:9: error: reference to 'prev' is ambiguous
   31 |         prev.resize(a.size() + 2, 'a');
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:7:14: note:                 'std::vector<char> prev'
    7 | vector<char> prev(a.size() + 2, 'a');
      |              ^~~~
a.cc:59:24: error: reference to 'prev' is ambiguous
   59 |                 res += prev[k];
      |                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:7:14: note:                 'std::vector<char> prev'
    7 | vector<char> prev(a.size() + 2, 'a');
      |              ^~~~
a.cc: In function 'long long int dfs(long long int)':
a.cc:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^