Skip to content

Instantly share code, notes, and snippets.

@tburnam
Created August 4, 2016 17:58
Show Gist options
  • Save tburnam/c26f43006c07fcb7897e0137be30d28c to your computer and use it in GitHub Desktop.
Save tburnam/c26f43006c07fcb7897e0137be30d28c to your computer and use it in GitHub Desktop.
AirBnB Practice Questions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBnBPractice
{
public static class Palindrome
{
public static string FindLongestPalindrome(string originalString)
{
string currentPalindrome = "";
string longestPalindrome = "";
int back = 0;
int front = 0;
int originalStringLength = originalString.Length - 1;
for (int index = 1; index < originalStringLength; index++)
{
front = index - 1;
back = index + 1;
while (front >= 0 && back < originalString.Length)
{
if (originalString[front] != originalString[back])
{
break;
}
currentPalindrome = originalString.Substring(front, back - front + 1);
if (currentPalindrome.Length > longestPalindrome.Length)
longestPalindrome = currentPalindrome;
front--;
back++;
}
}
return longestPalindrome;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment