Leap Year Checker - Problem

Given a year, determine whether it is a leap year or not.

A leap year is a year that is divisible by 4, except for years that are divisible by 100, unless they are also divisible by 400.

Rules for leap years:

  • If the year is divisible by 4, it might be a leap year
  • If the year is divisible by 100, it is not a leap year
  • If the year is divisible by 400, it is a leap year

Return true if the year is a leap year, false otherwise.

Input & Output

Example 1 — Leap Year (Divisible by 400)
$ Input: year = 2000
Output: true
💡 Note: 2000 is divisible by 400, so it's a leap year despite being divisible by 100
Example 2 — Not Leap Year (Century Year)
$ Input: year = 1900
Output: false
💡 Note: 1900 is divisible by 100 but not by 400, so it's not a leap year
Example 3 — Leap Year (Regular)
$ Input: year = 2024
Output: true
💡 Note: 2024 is divisible by 4 and not by 100, so it's a leap year

Constraints

  • 1 ≤ year ≤ 3000
  • Year is a positive integer

Visualization

Tap to expand
INPUTALGORITHMRESULT2000Year to CheckInput: Single Integer1Check if divisible by 42000 % 4 = 0 ✓2Check if divisible by 1002000 % 100 = 0 ✓3Check if divisible by 4002000 % 400 = 0 ✓4Apply leap year ruleDivisible by 400 = LeaptrueLeap YearFebruary has 29 daysOutput: BooleanKey Insight:Leap years follow a three-tier rule: divisible by 4, except centuries (÷100),except quarter-millennia (÷400). Use: (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)TutorialsPoint - Leap Year Checker | Combined Boolean Expression
Asked in
Amazon 25 Microsoft 18
23.5K Views
Medium Frequency
~8 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen