FastPrepCount Months Starting on Sunday
Problems/Count Months Starting on Sunday

Count Months Starting on Sunday

Walmart logoWalmart● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report fixes the main calculation to the years 2000 through 2024 and leaves out a function signature. Our version takes the inclusive year range as two integer parameters. The reported range is unchanged. Our version is about 96% the same as the reported question.

Given two years startYear and endYear, count the months in that inclusive range whose first day is a Sunday.

Use the Gregorian calendar. January 1, 2000 was a Saturday. A leap year is divisible by 400, or it is divisible by 4 but not by 100. February has 29 days in a leap year. Otherwise it has 28 days. April, June, September, and November have 30 days. Every other month has 31 days.

Calculate the weekdays directly. Do not use a date or calendar library.

Function

countSundayMonthStarts(startYear: int, endYear: int) → int

Examples

Example 1

startYear = 2000endYear = 2024return = 43

Step forward one month at a time from the Saturday given above. Exactly 43 months from January 2000 through December 2024 begin on a Sunday, so that is the answer.

Example 2

startYear = 2000endYear = 2000return = 1

Within 2000, October is the only month whose first day is Sunday.

Example 3

startYear = 2000endYear = 2004return = 8

Check the first day of every month in these five years. 8 of them fall on a Sunday, so that is the answer. Both 2000 and 2004 are leap years, so their February has the extra day.

Constraints

  • 2000 <= startYear <= endYear <= 9999.
  • Both endpoints are included.
  • Work out every weekday from the calendar rules above. Do not use a date or calendar library.

More Walmart Phone Screen questions

  • Longest Even-Length WordPHONE SCREEN · Seen Aug 2026
  • Range ModulePHONE SCREEN · Seen Aug 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Aug 2026
  • Sort Real Number StringsPHONE SCREEN · Seen Jan 2026
  • Check a Password Against a Supplied PolicyPHONE SCREEN · Seen Jun 2025
  • Convert a Restricted Function to an Arrow FunctionPHONE SCREEN · Seen Jun 2025
  • Repair One Missing Function Punctuation CharacterPHONE SCREEN · Seen Jun 2025
  • Can the Singer Perform the Song?PHONE SCREEN · Seen Mar 2025
  • Rooms With Two Other Entrances and a Treasure SuccessorPHONE SCREEN · Seen Mar 2025
  • First Dictionary Word from Note LettersPHONE SCREEN · Seen Aug 2022

Similar questions at other companies

  • Parking Fee CalculatorBreeze · PHONE SCREEN
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
  • Exponential Backoff DelaysWonderful · PHONE SCREEN
  • Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
  • Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
  • Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
All Walmart interview questionsSee Walmart hiring insights
Saved
class Solution {
    public int countSundayMonthStarts(int startYear, int endYear) {
        // Write your code here.
    }
}
Checking account…