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.
Easy java solution:-
Used a function to reverse a number and check their differnce is divisible by k or not.
class Result {
public static int rev(int num){
int rev = 0;
while(num != 0){
int digit = num % 10;
rev = rev*10 + digit;
num /= 10;
}
return rev;
}
public static int beautifulDays(int i, int j, int k) {
// Write your code here
int res = 0;
for(int index = i; index <= j; index++){
int rev = rev(index);
if(index > rev){
if((index - rev) % k == 0){
res++;
}
}else{
if((rev - index) % k == 0){
res++;
}
}
}
return res;
}
}
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 →
Easy java solution:- Used a function to reverse a number and check their differnce is divisible by k or not.
class Result {
}