The function recursively calls itself while removing the first character of the string until it reaches the base case. O(n) due to the recursion stack.