Simple BFS solution | Complete search
Visualize this problem in like a graph.\n1. Each node\'s value will be a possible string\n2. Each edge is an operation (\'add a\' or \'rotate by b\')\n3. Every 
Visualize this problem in like a graph.\n1. Each node\'s value will be a possible string\n2. Each edge is an operation (\'add a\' or \'rotate by b\')\n3. Every node will have only two children (\'add a\' or \'rotate by b\')\n\nNow we have to traverse this whole directed graph and find the minimum node, that means the lexicographically smallest string.\n\nSince there are directed edges and two children only, I thought at first that it\'ll be a binary tree. But nope. Since we have modulus in add a, hence doing add a operation can bring us back to some already seen string. Hence there may be directed cycles. Hence it is a graph. (Also rotate by b will obviously cause cycles to exist.)\n\nFinally,\nTo find minimum node in a graph we use BFS/DFS. C++ code below - \n\n```\nclass Solution {\npublic:\n    string add(string s, int a){\n        for(int i=1; i<s.size(); i+=2){\n            s[i] = \'0\'+(s[i]-\'0\'+a)%10;\n        }\n        return s;\n    }\n    string rot(string s, int b){\n        rotate(s.begin(), s.end()-b, s.end());\n        return s;\n    }\n    string findLexSmallestString(string s, int a, int b) {\n        set<string> visited;\n        string ans = s;\n        queue<string> q;\n        \n        q.push(s);\n        while(!q.empty()){\n            string curr = q.front();\n            q.pop();\n            \n            if(visited.count(curr)>0) continue;\n            else visited.insert(curr);\n            \n            //work on curr\n            ans = min(ans,curr);\n            \n            //child node 1\n            q.push(add(curr,a));\n            \n            //child node 2\n            q.push(rot(curr,b));\n        }\n        \n        return ans;\n    }\n};\n```\n\nNote : C++ automatically compares strings lexicographically when I use min() function.\n\nP.S : Please suggest if any changes/improvements/corrections are required.
[]