Javascript - Recursion
Intuition\nMy initial thoughts involve manipulating the input string \'s\' by applying two main operations: \'add\' and \'rotate\'. The \'add\' operation involv
# Intuition\nMy initial thoughts involve manipulating the input string \'s\' by applying two main operations: \'add\' and \'rotate\'. The \'add\' operation involves modifying specific digits within the string, while the \'rotate\' function reorders the characters.\n\n# Approach\nThe function \'add\' iterates through the string, applying specific transformations to certain digits based on their positions. Meanwhile, the \'rotate\' function reorganizes the string by slicing and rearranging the characters.\n\nThe main part of the code \'applyOperation\' applies these operations recursively and maintains the smallest lexically ordered string found so far.\n\n# Complexity\n- Time complexity:\n    O(k * n), where \'k\' is the number of unique combinations of \'add\' and \'rotate\' operations\n\n- Space complexity:\n    O(k), where \'k\' is the number of unique strings stored in the set\n# Code\n```\n/**\n * @param {string} s\n * @param {number} a\n * @param {number} b\n * @return {string}\n */\nvar findLexSmallestString = function(s, a, b) {\n    // Add function.\n    function add(str) {\n        let res = \'\';\n        for(let i = 0; i < str.length; i++) {\n            let digit = parseInt(str[i]);\n            if(i % 2 === 1) digit = (digit + a) % 10;\n            res+= digit;\n        }\n        return res;\n    }\n\n    // Rotate function\n    function rotate(str) {\n        return str.slice(b) + str.slice(0, b);    \n    }\n\n    let set = new Set();\n    let ans = s;\n    const applyOperation = (value) => {\n        if(set.has(value)) return; // Going throught a loop, it ends here\n        set.add(value);\n        // Compare strings.\n        if(ans > value) ans = value;\n        // Recursive using both operations.\n        applyOperation(add(value));\n        applyOperation(rotate(value));\n    }\n\n    applyOperation(s);\n\n    return ans;\n};\n```
['Recursion', 'JavaScript']