Leap Year

Easy · rating 950 · math, implementation

Read a year. Print YES if it is a leap year, otherwise NO. A year is a leap year if it is divisible by 4, except century years, which must be divisible by 400.

Editorial

Leap Year applies the Gregorian rule: a year is a leap year if it's divisible by 4, except centuries, which must also be divisible by 400. So 2000 qualifies but 1900 does not.

leap = year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
print('YES' if leap else 'NO')

Complexity

Time: O(1). Space: O(1).

Open Leap Year in Code Arena →