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.
public static int beautifulDays(int i, int j, int k) {
int count = 0;
for (int day = i; day <= j; day++) {
int reversed = reverseNumber(day);
if (Math.abs(day - reversed) % k == 0) {
count++;
}
}
return count;
}
private static int reverseNumber(int num) {
int reversed = 0;
while (num > 0) {
reversed = reversed * 10 + num % 10;
num /= 10;
}
return reversed;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read input values
int i = scanner.nextInt();
int j = scanner.nextInt();
int k = scanner.nextInt();
// Compute and print the number of beautiful days
System.out.println(beautifulDays(i, j, k));
scanner.close();
}
}
`
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Beautiful Days at the Movies
You are viewing a single comment's thread. Return to all comments →
Much more optimal solution in java : `
import java.util.Scanner;
public class BeautifulDaysAtTheMovies {
} `