Funcia
Tutorialimplementationmath

Leap Year Check

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
0

Given a year, return true if it is a leap year and false otherwise. The rules:

  1. A year divisible by 4 is a leap year,
  2. except that a year divisible by 100 is not,
  3. except that a year divisible by 400 is.

Examples

yearresult
2024true
1900false
2000true

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

  • 1≤1 \le year ≤10,000\le 10{,}000

Expected complexity

Time
O(1)
Space
O(1)

Examples

yearExpected
2024true
1900false
2000true

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

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251000 msderived
Kotlin 2.4 (JVM)1200 msestimated
C# 14 (.NET 10)1200 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness10013verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.