Convert Date to Binary - Problem
Convert Date to Binary Representation
You are given a string
The Challenge:
• Parse the date string to extract year, month, and day
• Convert each component to its binary representation
• Remove any leading zeros from the binary strings
• Join them back in the format
Example:
• Year 2080 → 100000100000 (in binary)
• Month 02 → 10 (in binary)
• Day 29 → 11101 (in binary)
You are given a string
date representing a Gregorian calendar date in the yyyy-mm-dd format. Your task is to transform this date into its binary representation by converting each component (year, month, and day) to binary without any leading zeroes.The Challenge:
• Parse the date string to extract year, month, and day
• Convert each component to its binary representation
• Remove any leading zeros from the binary strings
• Join them back in the format
year-month-dayExample:
"2080-02-29" becomes "100000100000-10-11101"• Year 2080 → 100000100000 (in binary)
• Month 02 → 10 (in binary)
• Day 29 → 11101 (in binary)
Input & Output
example_1.py — Basic Date Conversion
$
Input:
"2080-02-29"
›
Output:
"100000100000-10-11101"
💡 Note:
Year 2080 converts to binary 100000100000, month 02 (which is 2) converts to 10, and day 29 converts to 11101. Join with hyphens to get the result.
example_2.py — Simple Date
$
Input:
"1900-01-01"
›
Output:
"11101101100-1-1"
💡 Note:
Year 1900 → 11101101100, month 1 → 1, day 1 → 1. Notice how leading zeros are removed from the original '01-01'.
example_3.py — Edge Case
$
Input:
"2000-12-31"
›
Output:
"11111010000-1100-11111"
💡 Note:
Year 2000 → 11111010000, month 12 → 1100, day 31 → 11111. Shows conversion of larger month and day values.
Constraints
- date.length == 10
- date[4] == date[7] == '-'
-
All other characters in
dateare digits - Date represents a valid Gregorian calendar date between year 1 and year 104
- The input will always be in the exact format yyyy-mm-dd
Visualization
Tap to expand
Understanding the Visualization
1
Parse the Date
Split '2080-02-29' into three components: year=2080, month=2, day=29
2
Convert Year
2080 in binary is 100000100000 (remove leading zeros automatically)
3
Convert Month
2 in binary is 10
4
Convert Day
29 in binary is 11101
5
Reassemble
Join with hyphens: '100000100000-10-11101'
Key Takeaway
🎯 Key Insight: This problem is simply about parsing and converting - split the date, convert each number to binary using built-in functions, and reassemble with hyphens.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code