Learn
Exam

Leap Year Determination

Difficulty
STARTER

Problem

A leap year is a year that includes February 29th, occurring every 4 years.
Given a specific year year, write a function solution that determines if the year is a leap year.

The rules for determining leap years are as follows:

  • A year is a leap year if it is divisible by 4.
  • However, a year is not a leap year if it is divisible by 100.
  • A year is a leap year if it is divisible by 400.

Constraints

  • year is a natural number between 1 and 4000 inclusive.
  • If year is a leap year, return the string YES; otherwise, return NO.

Test Case

Test Case Number year return
1 2000 "YES"
2 1900 "NO"
3 2024 "YES"

Explanation for Test Case 1

  • When year = 2000, it is divisible by 400, so it is a leap year. Return YES.

Explanation for Test Case 2

  • When year = 1900, it is divisible by 100 but not by 400, so it is not a leap year. Return NO.

Explanation for Test Case 3

  • When year = 2024, it is divisible by 4 but not by 100, so it is a leap year. Return YES.