Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Day-of-Week Logic

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Day-of-Week Logic. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Recursion Pharmaceuticals schedules experiment milestones using Gregorian calendar dates. Given a target date, a reference date with a known weekday, and the reference weekday, calculate the target date's weekday without using Python's date or calendar libraries.

Implement a function that supports dates before or after the reference date. Use the proleptic Gregorian calendar, including the rule that century years are not leap years unless divisible by 400.

Formal Specification

Input consists of two dates represented as [year, month, day], plus the reference weekday as one of Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday. Return the target date's weekday as a string.

The reference date is guaranteed to be valid, and the target date may occur on either side of it. The weekday supplied for the reference date is correct.

Constraints

  • 1 <= year <= 9999
  • Both dates are valid Gregorian dates.
  • The target date may be before, equal to, or after the reference date.
  • The reference weekday is one of the seven full English weekday names.
  • Do not use Python date or calendar libraries.

Function Signature

def weekday_from_reference(target_date, reference_date, reference_weekday):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output