Voting Eligibility - Problem
Given a person's birth date as a string in the format YYYY-MM-DD, determine if they are eligible to vote. A person is eligible to vote if they are 18 years or older.
If the person is eligible, return "Eligible". If they are not eligible, return the number of days until they become eligible as a string (e.g., "120").
Assume the current date is 2024-01-01 for all calculations.
Input & Output
Example 1 — Not Eligible Yet
$
Input:
birthDate = "2010-06-15"
›
Output:
"1627"
💡 Note:
Person born on 2010-06-15 will turn 18 on 2028-06-15. From current date 2024-01-01 to 2028-06-15 is 1627 days.
Example 2 — Just Became Eligible
$
Input:
birthDate = "2006-01-01"
›
Output:
"Eligible"
💡 Note:
Person born on 2006-01-01 turned 18 on 2024-01-01, which is exactly the current date. They are eligible to vote.
Example 3 — Long Time Eligible
$
Input:
birthDate = "1990-03-20"
›
Output:
"Eligible"
💡 Note:
Person born on 1990-03-20 turned 18 on 2008-03-20, which is long before current date 2024-01-01. They are eligible.
Constraints
- Birth date is in valid YYYY-MM-DD format
- Birth date is not in the future (before 2024-01-01)
- 1900 ≤ birth year ≤ 2023
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code