Could you help me with my solution? I’m coding in C# and I used list for that problem, but I’m still getting NZEC or TLE error.
using System;
using System.Collections.Generic;
namespace Spoj
{
class Program
{
static void Main(string[] args)
{
int t = Convert.ToInt32(Console.ReadLine());
string pr = “0”;
List s = new List();
bool b = true;
for (int i = 0; i < t; i++)
{
pr = Console.ReadLine();
s.Add(0);
for (int j = 0; j < pr.Length; j++)
{
if(Convert.ToInt32(pr[j].ToString()) != 9 && j < pr.Length / 2)
{
b = false;
}
s.Add(Convert.ToInt32(pr[j].ToString()));
}
if(b == false)
{
s.RemoveAt(0);
}
Console.WriteLine(IsPalindrome(s));
s.Clear();
}
}
static string IsPalindrome(List<int> s)
{
string output = "";
int tmp = s.Count / 2, hlp = 1;
if (s.Count % 2 == 0)
{
if (s[tmp - 1] > s[tmp])
{
s[tmp] = s[tmp - 1];
}
else if (s[tmp - 1] < 9)
{
s[tmp - 1]++;
s[tmp] = s[tmp - 1];
}
else
{
s[tmp - 1]++;
while (s[tmp - hlp] > 8)
{
s[tmp - hlp] -= 10;
s[tmp - hlp - 1]++;
hlp++;
}
}
}
else
{
hlp = 0;
s[tmp]++;
if (s[tmp] > 9)
{
while (s[tmp - hlp] > 8)
{
s[tmp - hlp] -= 10;
s[tmp - hlp - 1]++;
hlp++;
}
}
}
for (int i = 0; i < s.Count; i++)
{
if (i <= tmp)
{
s[s.Count - 1 - i] = s[i];
}
output += s[i].ToString();
}
return output;
}
}
}