Weekday of a Valid Gregorian Date

Quick Overview

Weekday of a Valid Gregorian Date. Given day, month and year, return its weekday spelled exactly as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday.

Weekday of a Valid Gregorian Date

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Given day, month and year, return its weekday spelled exactly as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday. The date is valid. Use the source anchor that January 1, 1971 was Friday, and the Gregorian leap-year rule. ```cpp class Solution { public: string dayOfTheWeek(int day, int month, int year); }; ``` ### Examples **Example 1:** ```text Input: day = 2, month = 1, year = 1971 Output: "Saturday" Explanation: This is one day after the supplied Friday anchor. ``` **Example 2:** ```text Input: day = 1, month = 3, year = 1972 Output: "Wednesday" Explanation: There are365 days in1971 and60 days in January plus February1972. The425-day offset advances Friday by5 weekdays. ``` ### Constraints - The input is a valid Gregorian date with year between 1971 and 2100, inclusive. ### Contract considerations The source guarantees a valid date in its specified year range. Return exactly one of the listed weekday names. ```hint Read the boundary condition Which exact weekday spellings are allowed, and what are the earliest and latest permitted years? ``` ### Boundary reminders The source guarantees a valid date in its specified year range. Return exactly one of the listed weekday names.

Overview: Weekday of a Valid Gregorian Date. Given day, month and year, return its weekday spelled exactly as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Given day, month and year, return its weekday spelled exactly as Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday. The date is valid. Use the source anchor that January 1, 1971 was Friday, and the Gregorian leap-year rule.

class Solution {
public:
    string dayOfTheWeek(int day, int month, int year);
};

Examples

Example 1:

Input: day = 2, month = 1, year = 1971
Output: "Saturday"
Explanation: This is one day after the supplied Friday anchor.

Example 2:

Input: day = 1, month = 3, year = 1972
Output: "Wednesday"
Explanation: There are365 days in1971 and60 days in January plus February1972. The425-day offset advances Friday by5 weekdays.

Constraints

  • The input is a valid Gregorian date with year between 1971 and 2100, inclusive.

Contract considerations

The source guarantees a valid date in its specified year range. Return exactly one of the listed weekday names.

Boundary reminders

The source guarantees a valid date in its specified year range. Return exactly one of the listed weekday names.