Back to Practice Dashboard
Python BasicsEasy

Leap year or not

Learn how to solve the 'Leap year or not' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function is_leap_year(year) that takes an integer year and returns True if the year is a leap year, or False otherwise. A year is a leap year if it is divisible by 4 but not by 100, except when it is also divisible by 400.

Constraints
  • 1 <= year <= 10^5

Examples

Example 1
Input
year = 2024
Output
True
Explanation

2024 is divisible by 4 and not by 100, so it is a leap year.

Example 2
Input
year = 1900
Output
False
Explanation

1900 is divisible by 100 but not by 400, so it is not a leap year.

Example 3
Input
year = 2000
Output
True
Explanation

2000 is divisible by 400, so it is a leap year.

Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor