Convert Date to Binary - Problem
Convert Date to Binary Representation

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-day

Example: "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 date are 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
Date to Binary ConversionInput Date2080-02-29Year: 2080Decimal to Binary2080 = 2048 + 32= 2^11 + 2^5100000100000Month: 02 → 2Decimal to Binary2 = 2^110Day: 29Decimal to Binary29 = 16+8+4+1= 2^4+2^3+2^2+2^011101Final Binary Result100000100000-10-11101Join with hyphens⚡ Built-in functions like bin() make this conversion efficient!
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.
Asked in
Google 15 Amazon 12 Microsoft 8 Apple 5
22.5K Views
Medium Frequency
~8 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen