Day of the Week Years Later
Updated
Problem statement
Today is the date day/month/year, and it is a weekday. Return the day of the week of the same day and month exactly years years later.
Days of the week are written in full with a capital first letter: "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" or "Sunday".
Use the Gregorian calendar. A year is a leap year if it is divisible by 4, except years divisible by 100 that are not divisible by 400. A leap year has 366 days because it includes 29 February; other years have 365 days.
Function
weekdayAfterYears(day: int, month: int, year: int, weekday: String, years: int) → StringExamples
Example 1
day = 8month = 7year = 2022weekday = "Friday"years = 10return = "Thursday"Ten ordinary years would be 3650 days. Between the two dates there are three 29 Februaries, in 2024, 2028 and 2032, so the gap is 3653 days. That is 521 full weeks and 6 extra days, and six days after a Friday is a Thursday.
Example 2
day = 1month = 1year = 2000weekday = "Saturday"years = 1return = "Monday"The year 2000 is divisible by 400, so it is a leap year, and going from 1 January 2000 to 1 January 2001 passes 29 February 2000. The gap is 366 days, which is 52 weeks and 2 days. Two days after Saturday is Monday.
Example 3
day = 1month = 3year = 2096weekday = "Thursday"years = 8return = "Saturday"From 1 March 2096 to 1 March 2104 the years whose February could hold a 29th are 2100 and 2104. 2100 is divisible by 100 and not by 400, so it is not a leap year and has no 29 February. Only the leap day of 2104 counts, so the shift is 8 + 1 = 9 days, which is 2 days after removing a full week. Two days after Thursday is Saturday.
Constraints
1900 <= year <= 21001 <= month <= 121 <= day <= 311 <= years <= 1000day,monthandyearform a real date, and it is not 29 February.weekdayis the real day of the week of that date.
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Sqrt(x)LinkedIn · PHONE SCREENLinkedIn interview questions
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Circular Primes Below a LimitAmazon · PHONE SCREEN
- Palindrome NumberKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Streaming AverageXantium · PHONE SCREEN
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Employee Count Median, Mean and ModeClay · PHONE SCREEN