// Time and space complexity is O(n) where n is the size of the input string.