Easy to understand, beats 100%
Intuition\nThe problem is to find the lexicographically smallest string that can be obtained by performing a specific substring operation. The operation allows 
## Intuition\nThe problem is to find the lexicographically smallest string that can be obtained by performing a specific substring operation. The operation allows replacing every character of a chosen non-empty substring by the previous character in the alphabetical order, except for \'a\', which can be changed to \'z\'. The given solution iteratively searches for the first occurrence of a character that is not \'a\', as it represents the starting point for potential transformations. If the entire string consists of \'a\'s, the solution transforms the last \'a\' to \'z\' to minimize the string lexicographically. If not, it looks for the position where the next \'a\' occurs after the identified start, indicating the end of the substring to transform. The transformation decreases each character\'s ASCII code by 1, effectively rolling it back in the alphabet.\n\n## Approach\n1. Iterate through the string to find the first character that is not \'a\'.\n2. If the entire string is \'a\'s, replace the last character with \'z\' and return.\n3. Find the index of the next \'a\' after the initial non-\'a\' character, indicating the end of the substring to transform.\n4. Define a `convert` function that decrements the ASCII code of each character in the substring, rolling it back in the alphabet.\n5. Apply the `convert` function to the identified substring and concatenate it with the unchanged parts of the original string.\n\n## Complexity\n- **Time Complexity**: O(n) - The algorithm iterates over each character of the string at most twice (once to find the start of the substring to convert and another time during the conversion).\n- **Space Complexity**: O(n) - The `convert` function creates a new string which, in the worst case, can be as long as the original string.\n\n# Code\n```\nfunction smallestString(s: string): string {\n    let i = 0;\n    while (i < s.length) {\n        if (s[i] !== \'a\') {\n            break;\n        }\n\n        i++;\n    }\n    if (i === s.length) {\n        return s.slice(0, s.length - 1) + \'z\';\n    }\n\n    const end = s.indexOf(\'a\', i);\n    const convert = (str: string) => {\n        return str\n            .split(\'\')\n            .map((char) => String.fromCharCode(char.charCodeAt(0) - 1))\n            .join(\'\');\n    };\n\n    if (end === -1) {\n        return s.slice(0, i) + convert(s.slice(i));\n    }\n    return s.slice(0, i) + convert(s.slice(i, end)) + s.slice(end);\n}\n```
['TypeScript']