Easy Backtracking [C++]
Try all the combinations by adding a one time and rotating by b another time, on the same string.\n Since we need to take mod (%) after adding b, we will not ge
* Try all the combinations by adding `a` one time and rotating by `b` another time, on the same string.\n* Since we need to take mod (`%`) after adding `b`, we will not get infinite number of combinations, the search space will exhaust at a time.\n*  We just have to keep track of all the strings searched till that point of time.\n*  We keep the minimum string in the `res`.\n\n```\nclass Solution {\n    int n;\n    unordered_set<string> set;\npublic:\n    string findLexSmallestString(string s, int a, int b) {\n        n = s.length();\n        string res(n, \'9\');\n\t\t//just to create a string with maximum possible number\n        backtrack(s, a, b, res);\n        return res;\n    }\n    void backtrack(string& s, int a, int b, string& res) {\n        if(set.count(s)) return;\n        set.emplace(s);\n        if(s < res) {\n            res = s;\n        }\n        string s1 = s;\n\t\t//this string is for addition with a\n        for(int i = 1; i < n; i+=2) {\n            int c = s1[i] - \'0\';\n            s1[i] = ((c+a)%10) + \'0\';\n        }\n        string s2 = s.substr(n-b, b) + s.substr(0, n-b);\n\t\t//this string is for rotation by b\n        backtrack(s1, a, b, res);\n        backtrack(s2, a, b, res);\n    }\n};\n```\n**Please upvote if you found it helpful :)**
[]