Python BFS and DFS Solutions
Code\npython [BFS]\nclass Solution:\n    def findLexSmallestString(self, s: str, a: int, b: int) -> str:\n        def add(arr):\n            return tuple((n + a
# Code\n```python [BFS]\nclass Solution:\n    def findLexSmallestString(self, s: str, a: int, b: int) -> str:\n        def add(arr):\n            return tuple((n + a) % 10 if i % 2 else n for i, n in enumerate(arr))\n\n        def rotate(arr):\n            return arr[-b:] + arr[:-b]    \n\n        s = tuple(int(n) for n in s)\n        smallest = s[:1] + s[1:]\n        visited = set()\n        stack = [s]\n        while stack:\n            current = stack.pop()\n            smallest = min(smallest, current)\n            visited.add(current)\n            added = add(current)\n            rotated = rotate(current)\n            if added not in visited:\n                stack.append(added)\n            if rotated not in visited:\n                stack.append(rotated)\n        return \'\'.join(str(n) for n in smallest)  \n        \n```\n```python [DFS]\nclass Solution:\n    def findLexSmallestString(self, s: str, a: int, b: int) -> str:\n        def add(arr):\n            return tuple((n + a) % 10 if i % 2 else n for i, n in enumerate(arr))\n\n        def rotate(arr):\n            return arr[-b:] + arr[:-b]\n        \n        def dfs(arr):\n            nonlocal smallest\n            smallest = min(smallest, arr)\n            visited.add(arr)\n            added = add(arr)\n            rotated = rotate(arr)\n            if added not in visited:\n                dfs(added)\n            if rotated not in visited:\n                dfs(rotated)\n                \n        s = tuple(int(n) for n in s)\n        smallest = s[:1] + s[1:]\n        visited = set()\n        dfs(s)\n        return \'\'.join(str(n) for n in smallest)\n```
['Python3']