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 think your code was wrong. I think you lost variable i's value, because in while loop it changes its value to 0.
I think this has to work fine.
int count = 0;
for (; i <= j; i++) {
int num = i;
int revNum = 0;
while (num > 0) {
revNum = 10 * revNum + num % 10;
num /= 10;
}
if (Math.abs(i - revNum) % k == 0)
count++;
}
return count;
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 think your code was wrong. I think you lost variable i's value, because in while loop it changes its value to 0.
I think this has to work fine.