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\)

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
16 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Points:30
6 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms