We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It’s a tricky question to answer. We have three main conditions for leap years:
* If the year is evenly divisible by 4, it is a leap year, unless: (year % 4 == 0)
* If the year is evenly divisible by 100, it is NOT a leap year, unless: (year % 100 != 0)
* However, if the year is also evenly divisible by 400, then it is a leap year: (year % 400 == 0)
To determine if a year is a leap year, conditions 1 and 2 must both evaluate to True or False. Otherwise, compare condition 3 (year % 400 == 0) directly.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Write a function
You are viewing a single comment's thread. Return to all comments →
It’s a tricky question to answer. We have three main conditions for leap years: * If the year is evenly divisible by 4, it is a leap year, unless: (year % 4 == 0) * If the year is evenly divisible by 100, it is NOT a leap year, unless: (year % 100 != 0) * However, if the year is also evenly divisible by 400, then it is a leap year: (year % 400 == 0)
To determine if a year is a leap year, conditions 1 and 2 must both evaluate to True or False. Otherwise, compare condition 3 (year % 400 == 0) directly.