Given a month (1-12) and a year, return the number of days in that month. Account for leap years when calculating the days in February. A year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400.

Examples:

Input: month = 2, year = 2024 Output: 29 Explanation: 2024 is a leap year, so February has 29 days Input: month = 2, year = 2023 Output: 28 Explanation: 2023 is not a leap year, so February has 28 days Input: month = 1, year = 2024 Output: 31 Explanation: January always has 31 days Input: month = 4, year = 2024 Output: 30 Explanation: April always has 30 days Input: month = 12, year = 2024 Output: 31 Explanation: December always has 31 days
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay August 2026

Contest runs August 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In