Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 312 ms):
import java.io.*;

import java.util.*;



public class Main{

    public static void main(String[] args) throws Exception {

        if (System.getProperty("ONLINE_JUDGE") == null) {

            System.setIn(new FileInputStream("input.txt"));

            System.setOut(new PrintStream(new FileOutputStream("output.txt")));

        }



        FastReader sc = new FastReader();

        PrintWriter out = new PrintWriter(System.out);



        int t = sc.nextInt(); 

        //template

        while (t-- > 0) {

            String num = sc.next();

            int[] nums = new int[num.length()];

            int idx=0;

            while(idx<num.length()){

                nums[idx] = num.charAt(idx)-'0';

                idx++;

            }

            for(int i=1;i<num.length();i++){

                idx=i;

                while(idx>=1&&nums[idx-1]+1<nums[idx]&&nums[idx]>0){

                    int val = nums[idx];

                    nums[idx]=nums[idx-1];

                    nums[idx-1]=val-1;

                    idx--;

                }

                //System.out.println(Arrays.toString(nums));

            }

            StringBuilder sb = new StringBuilder();

            for(int i:nums)sb.append(i);

            System.out.println(sb);

        }



        out.flush(); 

    }



    // Optimized Fast Input Reader

    static class FastReader {

        BufferedReader br;

        StringTokenizer st;



        public FastReader() {

            br = new BufferedReader(new InputStreamReader(System.in));

        }



        String next() {

            while (st == null || !st.hasMoreElements()) {

                try {

                    st = new StringTokenizer(br.readLine());

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }



        int nextInt() {

            return Integer.parseInt(next());

        }



        long nextLong() {

            return Long.parseLong(next());

        }



        double nextDouble() {

            return Double.parseDouble(next());

        }



        String nextLine() {

            String str = "";

            try {

                str = br.readLine();

            } catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }

    }

}

class Pair<K,V>{

    K key;

    V value;

    public Pair(K key,V value){

        this.key=key;

        this.value=value;

    }

    public K getKey(){

        return this.key;

    }

    public V getValue(){

        return this.value;

    }

}

Solution 2 (runtime: 296 ms):
import java.util.*;



public class Main {

public static void main(String []args) {

Scanner sc=new Scanner(System.in);

int t=sc.nextInt();

while(t-->0){

String s = sc.next();

char[] arr = s.toCharArray();



for (int i = 0; i < arr.length; i++) {

int best = arr[i] - '0', pos = i;



for (int j = i; j < Math.min(i + 10, arr.length); j++) {

if ((arr[j] - '0') - (j - i) > best) {

best = (arr[j] - '0') - (j - i);

pos = j;

}

}



while (pos > i) {

char temp = arr[pos];

arr[pos] = arr[pos - 1];

arr[pos - 1] = temp;

pos--;

}



arr[i] = (char) (best + '0');

}



System.out.println(new String(arr));

}

}

}