Given two years Y1 and Y2 where 103 ≤ Y1 ≤ Y2 ≤ 106, the task is to find and print all the dates which are palindromes between the given years.
Input: Y1 = 2001, Y2 = 2005
Input: Y1 = 5000, Y2 = 5010
Approach: Since the first four digits (i.e. the day and the month) have to be the reverse of the last four digits (the year) in order for the date to be a palindrome. So, every year will have at most one palindrome date. In order to find the dates, for every year reverse the year number and check whether the date formed is valid or not. If it is valid then print it.
Below is the implementation of the above approach:
- Write a program to print all permutations of a given string
- Print all combinations of balanced parentheses
- Print all combinations of points that can compose a given number
- Print all sequences of given length
- Given a number, find the next smallest palindrome
- Print all permutations in sorted (lexicographic) order
- Efficient program to print all prime factors of a given number
- Check if a number is Palindrome
- Print all possible combinations of r elements in a given array of size n
- Print all possible words from phone digits
- Check if binary representation of a number is palindrome
- Print squares of first n natural numbers without using *, / and -
- Print all increasing sequences of length k from first n natural numbers
- OLA Cabs Interview Experience | Set 2 (For Android - 1.5 Years)
- Find number of days between two given dates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.