24Dec/111
Interview Questions #3 – Reversing a String – C Sharp C# Visual Studio 2010
In this tutorial I show you how to solve common interview questions. In this specific video I go over the simple interview question of reversing a string and talk about what might happen if the interviewer asks a more difficult problem afterwards. WEBSITE: www.Quack-Ware.com
January 19th, 2012 - 08:27
I just had to note that if you were to simply split the original string into a new array of strings all you would need to do would be to create a loop for the words themselves making it much more efficient using a much smaller array length.
It could get even more complicated if you were to use generics etc.
Here is my snippet although I am sure you can do better.
private static string newReverse(string str)
{
string[] newStr = str.Split(‘ ‘);;
int j = newStr.Length -1;
for (int i = 0; i < newStr.Length/2; i++)
{
string temp = newStr[i];
newStr[i] = newStr[j];
newStr[j] = temp;
}
string revStr = "";
for (int x = 0; x < newStr.Length; x++)
{
revStr += " ";
revStr += newStr[x];
}
return revStr;
}