Problem: 2050D - Digital string maximization
Language: c++23 

Code 1:
// /**
// *    author:  _isomorphism
// *    created: 19.12.2024 16:30:22
// **/
// 
// Problem: D. Digital string maximization
// Contest: Codeforces - Codeforces Round 991 (Div. 3)


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)2e18
#define endl '\n'

const int mod = 1e9 + 7;
const int MOD = 998244353;

vector<int> binrep(int n) {
  if (n == 0)
    return {0};
  vector<int> b;
  while (n > 0) {
    b.insert(b.begin(), n % 2);
    n /= 2;
  }
  return b;
}

int binpow(int base, int exp, int m) {
  int result = 1;
  base = base % m;
  while (exp > 0) {
    if (exp % 2 == 1) {
      result = (result * base) % m;
    }
    base = (base * base) % m;
    exp = exp / 2;
  }
  return result;
}


//bool check(int x){
//
//}
//
//int search(int k) {
//  int pos = 0, max = INF;
//  for (int i = max; i >= 1; i /= 2) {
//    while (check(pos + i)) pos += i;
//  }
//  return pos;
//}
//
//int search(int k) {
//    int low = 0, high = INF, ans = -1;
//    while (low <= high) {
//        int mid = low + (high - low) / 2;
//        if (check(mid)) {
//            ans = mid;
//            high = mid - 1;
//        } else {
//            low = mid + 1;
//        }
//    }
//    return ans;
//}

void solve() {
	string s; cin >> s;
	int n = s.length();
	int idx = 0;
	char m = '0', temp;
	string ans = "";
	for(int i = 0; i < n; i++){
		m = '0';
		for(int j = 0; j < 9 && j < n; j++){
			temp = (char)((int)s[j] - j);
			if(m < temp){
				m = temp;
				idx = j;
			}
		}
		ans += m;
		s.erase(s.begin() + idx);
	}
	cout << ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test = 1;
  cin >> test;

  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}

Code 2:
// /**
// *    author:  _isomorphism
// *    created: 19.12.2024 16:30:22
// **/
// 
// Problem: D. Digital string maximization
// Contest: Codeforces - Codeforces Round 991 (Div. 3)


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)2e18
#define endl '\n'

const int mod = 1e9 + 7;
const int MOD = 998244353;

vector<int> binrep(int n) {
  if (n == 0)
    return {0};
  vector<int> b;
  while (n > 0) {
    b.insert(b.begin(), n % 2);
    n /= 2;
  }
  return b;
}

int binpow(int base, int exp, int m) {
  int result = 1;
  base = base % m;
  while (exp > 0) {
    if (exp % 2 == 1) {
      result = (result * base) % m;
    }
    base = (base * base) % m;
    exp = exp / 2;
  }
  return result;
}


//bool check(int x){
//
//}
//
//int search(int k) {
//  int pos = 0, max = INF;
//  for (int i = max; i >= 1; i /= 2) {
//    while (check(pos + i)) pos += i;
//  }
//  return pos;
//}
//
//int search(int k) {
//    int low = 0, high = INF, ans = -1;
//    while (low <= high) {
//        int mid = low + (high - low) / 2;
//        if (check(mid)) {
//            ans = mid;
//            high = mid - 1;
//        } else {
//            low = mid + 1;
//        }
//    }
//    return ans;
//}

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int test = 1;
  cin >> test;

  while (test--) {
    solve();
    cout << '\n';
  }
  return 0;
}

Answer: 2