Created
March 19, 2019 11:54
-
-
Save arun-cm/d46451f3a7760d9efa751e32d95d1bc4 to your computer and use it in GitHub Desktop.
Revisions
-
arun-cm created this gist
Mar 19, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Text.RegularExpressions; using System.Text; using System; class Solution { // Complete the palindromeIndex function below. static int palindromeIndex(string s) { int maxIndex = s.Length/2; for (int i = 0; i < maxIndex; i++) { if(s[i] != s[s.Length -1 - i]) { if(s.Substring(i + 1, 2) == Reverse(s.Substring((s.Length - 1 - i)-1, 2)) ) { return i; } else { return (s.Length - 1 - i); } return i; } } return -1; } static string Reverse(string str) { string reverse = ""; int Length = 0; Length = str.Length - 1; while(Length>=0) { reverse = reverse + str[Length]; Length--; } return reverse; } static void Main(string[] args) { TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true); int q = Convert.ToInt32(Console.ReadLine()); for (int qItr = 0; qItr < q; qItr++) { string s = Console.ReadLine(); int result = palindromeIndex(s); textWriter.WriteLine(result); } textWriter.Flush(); textWriter.Close(); } }