Print all palindrome dates between the given years
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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
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: