Day of the Week - Problem

Given a date, return the corresponding day of the week for that date.

The input is given as three integers representing the day, month and year respectively.

Return the answer as one of the following values: {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

Note: January 1, 1971 was a Friday.

Input & Output

Example 1 — Basic Case
$ Input: day = 31, month = 12, year = 1999
Output: Friday
💡 Note: December 31, 1999 was a Friday. We can verify this by counting days from January 1, 1971 or using Zeller's formula.
Example 2 — Leap Year
$ Input: day = 29, month = 2, year = 2000
Output: Tuesday
💡 Note: February 29, 2000 was a Tuesday. Year 2000 is a leap year (divisible by 400).
Example 3 — Reference Date
$ Input: day = 1, month = 1, year = 1971
Output: Friday
💡 Note: January 1, 1971 was a Friday as given in the problem statement.

Constraints

  • 1 ≤ day ≤ 31
  • 1 ≤ month ≤ 12
  • 1971 ≤ year ≤ 2100
  • The given date is guaranteed to be valid

Visualization

Tap to expand
Day of the Week Problem OverviewInputday = 31month = 12year = 1999ProcessMethod 1: Count daysfrom Jan 1, 1971Method 2: Zeller formulaOutputFridayTwo main approaches: Day counting or mathematical formulaBoth achieve O(1) time and space complexity
Understanding the Visualization
1
Input
Three integers: day, month, year
2
Process
Calculate using reference point or mathematical formula
3
Output
Day name string
Key Takeaway
🎯 Key Insight: Use reference date counting or mathematical formulas to avoid complex calendar logic
Asked in
Amazon 25 Microsoft 20 Google 15
32.0K Views
Medium Frequency
~15 min Avg. Time
850 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