C++ very simple BFS
Explaination:\n\tthe question asks to find the smallest string given an original string, and two type of operation that we can perform\n\twe can perform the ope
**Explaination:**\n\tthe question asks to find the smallest string given an original string, and two type of operation that we can perform\n\twe can perform the operations on the string unlimited amount of time, so it is hard to simulate that process(when do we stop applying the operation?)\n\tBut after some observation we can see that if we apply operation A or B continously on the string, it will end up like a loop\n\n----\t\n>   let\'s say s = 5252, a = 5\n>\tif we apply A (Add a to all odd indices of s (0-indexed)): \n>\t5252 -> 5**7**5**7** -> 5**2**5**2** -> 5**7**5**7**\n>\t--- loop1---    ----loop2---\n>\tif a = 3\n>\t**5252** -> 5555 -> 5858 ->5151 -> 5454 -> 5757 -> 5050 -> 5353 -> 5656 -> 5959 -> **5252** (we are back!)\n----\nThe chain will no exceed 10, **it will eventually loops back to the original string**\nso does the operation B (Rotate s to the right by b positions), if u keep applying the same operation it will goes like a loop as well , and it will not exceed N( N is the length of s the worst case is when b is 1, and u can shift N - 1 times)\nafter these thought process , we can tell that the states are not infinite, we just need to find out a way to enumerate all possibilities, what I did in the following code is to perform a  BFS and enumerate all possible sequences\n\n\n\n```\n    string findLexSmallestString(string s, int a, int b) {\n        string smallest = s;\n        const int N = s.size();\n        queue<string> q;\n        unordered_set<string> seen;\n\n        q.push(s);\n        seen.insert(s);\n        while (!q.empty()) {\n            string cur = q.front(); q.pop();\n            if (cur < smallest) smallest = cur; // we found a new state, lets check if it\'s the smallest \n            for (int i = 1; i < N; i += 2)  // operation A\n                cur[i] = ((cur[i] - \'0\') + a) % 10 + \'0\';\n            if (seen.insert(cur).second) q.push(cur); // only insert if this is a new state (otherwise we will stuck in the loop)\n            cur = (cur.substr(N - b) + cur.substr(0, N - b)); // operation B\n            if (seen.insert(cur).second) q.push(cur); // same \n        }\n        return smallest;\n    }\n```
[]