Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Printing Leap Years

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

Your question is Printing Leap Years. 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

MORSE simulation timelines may need a list of calendar years that contain an extra day. Given an inclusive range of years, return every leap year in that range in ascending order.

A year is a leap year under the Gregorian calendar if it is divisible by 4, except for century years, which must also be divisible by 400. For example, 2000 is a leap year, while 1900 is not.

Formal Specification

Implement leap_years_since(start_year, end_year).

  • Input: Two integers, start_year and end_year, representing the inclusive range to inspect.
  • Output: A list of integers containing all leap years from start_year through end_year, in ascending order.

Constraints

  • 1 <= start_year <= end_year <= 10^6
  • The range is inclusive
  • Return an empty list when no leap year exists

Function Signature

def leap_years_since(start_year, end_year):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output