A special date
Practice
3.1 (23 votes)
Algorithms
Basics of greedy algorithms
Greedy algorithms
Problem
76% Success 5592 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
A special birth date is $$D$$. Your task is to find the last palindrome date that comes before a date $$D$$.
You are given a date $$D$$ in the string format. The date format is as follows:
- A valid date $$D$$ is of length 8 and in the $$ddmmyyyy$$ format.
- A valid date ranges between 01 to 30.
- A valid month ranges between 01 to 12.
- A valid year ranges between 0001 to 9999.
Input format
- The first line contains an integer $$T$$ denoting the number of test cases.
- The first line of each test case contains a string $$D$$ that denotes the special birth date.
Output format
For each test case, print the valid palindrome date in a new line. If there is no possible palindrome date that comes before D, then print -1.
Constraints
\(1 \le T \le 10000\)
Explanation
For the only testcase, 29-11-1192 is the last palindrome date which comes before 21-08-2000.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
1.Factors
Points:30
10 votes
Tags:
SortingAlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
9 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:30
5 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output