Language: C++

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int max_length = 200000;
char a[max_length + 1];
char result[max_length + 1];
int index[26][max_length + 1];
int first[26];
int length;

void solve() {
	length = strlen(a);
	for (int i = 0; i < 26; i++) {
		fill(index[i], index[i] + length, length);
	}

	for (int i = 0; i < length; i++) {
		int x = a[i] - 'a';

		index[x][first[x]] = i;
		first[x]++;
	}
	fill(first, first + 26, 0);

	int pos = 0;
	char *it = result;
	while (pos < length) {
		int best = -1;

		for (int i = 0; i < 26; i++) {
			int &j = first[i];
			while (index[i][j] < pos) {
				j++;
			}

			if (best == -1 || (index[i][j] > index[best][first[best]])) {
				best = i;

				if (index[i][j + 1] == length) {
					break;
				}
			}
		}

		*it++ = (char)('a' + best);
		pos = index[best][first[best]] + 1;
	}

	*it = '\0';
}

int main() {

	cin >> a;

	solve();

	cout << result << "\n";

	return 0;
}

Compiler output:
a.cc:10:29: error: 'int index [26][200001]' redeclared as different kind of entity
   10 | int index[26][max_length + 1];
      |                             ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:3:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void solve()':
a.cc:17:27: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   17 |                 fill(index[i], index[i] + length, length);
      |                           ^
a.cc:17:37: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   17 |                 fill(index[i], index[i] + length, length);
      |                                     ^
a.cc:23:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   23 |                 index[x][first[x]] = i;
      |                      ^
a.cc:35:37: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   35 |                         while (index[i][j] < pos) {
      |                                     ^
a.cc:39:49: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   39 |                         if (best == -1 || (index[i][j] > index[best][first[best]])) {
      |                                                 ^
a.cc:39:63: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   39 |                         if (best == -1 || (index[i][j] > index[best][first[best]])) {
      |                                                               ^
a.cc:42:42: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   42 |                                 if (index[i][j + 1] == length) {
      |                                          ^
a.cc:49:28: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   49 |                 pos = index[best][first[best]] + 1;
      |                            ^