Convert Date to Binary - Problem

You are given a string date representing a Gregorian calendar date in the yyyy-mm-dd format.

date can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in year-month-day format.

Return the binary representation of date.

Input & Output

Example 1 — Standard Date
$ Input: date = "2019-06-10"
Output: "11111100011-110-1010"
💡 Note: 2019 in binary is 11111100011, 06 in binary is 110, 10 in binary is 1010. Join with dashes: 11111100011-110-1010
Example 2 — Early Year
$ Input: date = "1900-01-01"
Output: "11101101100-1-1"
💡 Note: 1900 in binary is 11101101100, 01 in binary is 1, 01 in binary is 1. Result: 11101101100-1-1
Example 3 — Large Numbers
$ Input: date = "2000-12-31"
Output: "11111010000-1100-11111"
💡 Note: 2000 in binary is 11111010000, 12 in binary is 1100, 31 in binary is 11111. Result: 11111010000-1100-11111

Constraints

  • date.length == 10
  • date[4] == date[7] == '-'
  • All other characters in date are digits
  • date represents a valid Gregorian calendar date between 1000-01-01 and 9999-12-31

Visualization

Tap to expand
Convert Date to BinaryTransform yyyy-mm-dd to binary formatINPUT2019-06-10CONVERT TO BINARY20190610111111000111101010JOIN WITH DASHESOUTPUT11111100011-110-1010
Understanding the Visualization
1
Input
Date string in yyyy-mm-dd format: '2019-06-10'
2
Process
Convert each component (year, month, day) to binary
3
Output
Binary representation with dashes: '11111100011-110-1010'
Key Takeaway
🎯 Key Insight: Split date components and convert each number to binary without leading zeros
Asked in
Google 15 Microsoft 12 Amazon 8
12.4K Views
Medium Frequency
~8 min Avg. Time
543 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