Ad
  • Custom User Avatar

    There is no more effective way to solve this problem. At the very least, you would need to travese the string which takes O(N). For extra space complexity, the variable crypt to store each key-value pair has O(1) space complexity since its size is not dependent on the size of the input string. If not consdiering the output string to be returned, the space complexity would be O(1) as well.