I was asked a question in a recent interview to write a recursive function to reverse a string and whether an iterative version is better than recursive one for this particular algorithm. I am not sure how the recursive solution is worse/better than iterative one. Can anyone help me understand this?
Isn't the below code a tail recursive one?
public static string Reverse(string str)
{
return (str.Length <= 1 ? str : str[str.Length - 1]
+ Reverse(str.Substring(0, str.Length - 1)));
}