We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I got time out error too in C#. Resolved it only by adding this code:
int result = 0;
string rev = "";
int dif = 0;
int revNum = 0;
for (int n = i; n < j + 1; n++)
{
if (j > k)
{
dif = n;
rev = "";
while (dif >= 10)
{
rev = rev + (dif % 10).ToString();
dif = dif / 10;
}
rev = rev + dif.ToString();
if (rev == n.ToString())
{
result++;
}
else
{
revNum = Convert.ToInt32(rev);
if ((n - revNum) % k == 0) result++;
}
}
else
{
var poly = n.ToString();
if (poly.Length == 1) result++;
for (int l = 0; l < poly.Length / 2; l++)
{
if (poly[l] != poly[poly.Length - l - 1])
{
break;
}
if (l + 1 == poly.Length / 2)
{
result++;
}
}
}
}
return result;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Days at the Movies
You are viewing a single comment's thread. Return to all comments →
I got time out error too in C#. Resolved it only by adding this code: int result = 0; string rev = ""; int dif = 0; int revNum = 0; for (int n = i; n < j + 1; n++) { if (j > k) { dif = n; rev = ""; while (dif >= 10) { rev = rev + (dif % 10).ToString(); dif = dif / 10; } rev = rev + dif.ToString();