Greedy O(N) O(N) using
Approach\n Describe your approach to solving the problem. \nGreedy\n\n# Complexity\n- Time complexity: O(n)\n\n\n- Space complexity: O(n)\n\n\n\n# Code\njavascr
# Approach\n<!-- Describe your approach to solving the problem. -->\nGreedy\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n\n- Space complexity: $$O(n)$$\n\n\n\n# Code\n```javascript []\n/**\n * @param {string} s\n * @return {string}\n */\nvar smallestString = function(s) {\n  let i = 0\n  const n = s.length\n  let ans = s.split(\'\');\n\n  while(i < n && s[i] === \'a\') i++\n  if (i == n){\n    ans[n-1] = \'z\'\n    return ans.join(\'\')\n  }\n  while(i < n && s[i] !== \'a\'){\n    ans[i] = String.fromCharCode(s[i].charCodeAt(0) - 1)\n    i++\n  }\n  return ans.join(\'\')\n};\n```
['Greedy', 'JavaScript']