I was given 30 minutes to complete the following task in an interview for an entry level C# developer role, the closest I could get to was to find out if the characters in both sides of the current index matched each other.
Construct an array which takes in an string and determines if at index
(i) the substring tothe left of (i) when reversed, equals to the substring to the right of
(i).example: “racecar”
at index(3) the left substring is “rac” and when reversed equals to
the right substring “car”.return (i) if met with such condition, eslse return -1.
if string length is under 3, return 0;
if (str.Length < 3)
return -1;
for (int i = 0; i < str.Length - 1; i++)
{
if(str[i-1] == str [i+1])
return i;
}
return -1;
1 Answer