Tutorialimplementationmath
Leap Year Check
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Given a year, return true if it is a leap year and false otherwise. The rules:
- A year divisible by 4 is a leap year,
- except that a year divisible by 100 is not,
- except that a year divisible by 400 is.
Examples
| year | result |
|---|---|
2024 | true |
1900 | false |
2000 | true |
Example 1 — Divisible by 4 but not by 100.
Example 2 — Divisible by 100 but not by 400: not a leap year.
Example 3 — Divisible by 400: a leap year.
This is a tutorial problem: there are no performance tests, just return the correct value.
Function signature
solution(year: int) → bool
Constraints
-
year
Expected complexity
- Time
- O(1)
- Space
- O(1)
Examples
| year | Expected |
|---|---|
2024 | true |
1900 | false |
2000 | true |
Hint
Hint
All three rules fit in one condition: (year % 4 == 0 && year % 100 != 0) || year % 400 == 0. Try it on 2000,
1900 and 2024.
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1200 ms | estimated |
| C# 14 (.NET 10) | 1200 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 100 | 13 | verdict only |