package leetcode;

/**
 * https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations/
 */
public class Problem1625 {
    public String findLexSmallestString(String s, int a, int b) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1625 prob = new Problem1625();
        System.out.println(prob.findLexSmallestString("5525", 9, 2)); // "2050"
        System.out.println(prob.findLexSmallestString("74", 5, 1)); // "24"
        System.out.println(prob.findLexSmallestString("0011", 4, 2)); // "0011"
        System.out.println(prob.findLexSmallestString("43987654", 7, 3)); // "00553311"
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -268,15 +268,108 @@
     
-// TODO
+StringRef answer = new StringRef();%0A        findLexSmallestString(s, a, b, new HashSet%3C%3E(), answer);
 %0A   
@@ -384,11 +384,17 @@
 urn 
-nul
+answer.va
 l;%0A 
@@ -408,21 +408,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -422,269 +422,638 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem1625 prob = new Problem1625()
+class StringRef %7B%0A        private String val
 ;%0A    
+%7D%0A%0A
     
-System.out.println(prob.findLexSmallestString(%225525%22, 9, 2)); // %222050%22%0A        System.out.println(prob.findLexSmallestString(%2274%22, 5, 1)); // %2224%22%0A        System.out.println(prob.
+private static void findLexSmallestString(String s, int a, int b, Set%3CString%3E visited,%0A                                              StringRef minString) %7B%0A        if (visited.contains(s)) %7B%0A            return;%0A        %7D%0A        visited.add(s);%0A        char%5B%5D chars = s.toCharArray();%0A        for (int i = 1; i %3C s.length(); i += 2) %7B%0A            chars%5Bi%5D = (char) (((chars%5Bi%5D - '0' + a) %25 10) + '0');%0A        %7D%0A        String s1 = new String(chars);%0A        if (minString.val == null %7C%7C minString.val.compareTo(s1) %3E 0) %7B%0A            minString.val = s1;%0A        %7D%0A        
 find
@@ -1074,66 +1074,218 @@
 ing(
-%220011%22, 4, 2)); // %220011%22%0A        System.out.println(prob.
+s1, a, b, visited, minString);%0A        String s2 = s.substring(s.length() - b) + s.substring(0, s.length() - b);%0A        if (minString.val.compareTo(s2) %3E 0) %7B%0A            minString.val = s2;%0A        %7D%0A        
 find
@@ -1306,41 +1306,38 @@
 ing(
-%2243987654%22, 7, 3)); // %2200553311%22
+s2, a, b, visited, minString);
 %0A   

Solve problem 1625