🔴🟢Python3🤔1625. Lexicographically Smallest String 🥑Recursion🍱
\n\n# Intuition\nlist stack recursion\n\n# Approach\nlist stack recursion\n\n# Complexity\n- Time complexity:\nO(2^n)\n\n- Space complexity:\nO(2^n)\n\n# Code\n
![image.png](https://assets.leetcode.com/users/images/bee9b3c3-9935-41ec-b4ac-bc0026d2799e_1696760405.154087.png)\n\n# Intuition\nlist stack recursion\n\n# Approach\nlist stack recursion\n\n# Complexity\n- Time complexity:\n$$O(2^n)$$\n\n- Space complexity:\n$$O(2^n)$$\n\n# Code\n```\nclass Solution:\n\tdef findLexSmallestString(self, s: str, a: int, b: int) -> str:\n\t\t\'\'\'list stack recursion\'\'\'\n\t\t# Define Two Functions\n\t\t# Add Operation\n\t\tdef add(string):\n\t\t\tret = []\n\t\t\tfor i, c in enumerate(string):\n\t\t\t\tif i % 2:\n\t\t\t\t\tret.append(str((int(c) + a) % 10))\n\t\t\t\telse:\n\t\t\t\t\tret.append(c)\n\t\t\treturn "".join(ret)\n\n\t\t# Rotate Operation using nagetive slice\n\t\trotate = lambda string: string[-b:] + string[:-b]\n\n\t\tres = set()\n\t\tstack = [s]\n\t\twhile stack: \n\t\t\tcur = stack.pop() # current string\n\t\t\tres.add(cur) # add to res set\n\t\t\t# add and rotate separately\n\t\t\tfor val in [add(cur), rotate(cur)]:\n\t\t\t\tif val not in res:\n\t\t\t\t\tstack.append(val)\n\n\t\treturn min(res)\n```
['String', 'Depth-First Search', 'Breadth-First Search', 'Recursion', 'Python3']