आसान 0 हल किए गए 0% स्वीकृति

Leap Year

Check whether a year follows the Gregorian leap-year rule.

आप क्या सीखेंगे

  • Combine divisibility rules with and/or
  • Apply the century exception
  • Write a clear one-line condition

समस्या

अनुवाद दिखाएँ

A year divisible by 4 is a leap year unless it is also divisible by 100. Years divisible by 400 are leap years despite that exception. Apply this arithmetic rule to every allowed input year.

Implement leap_year(year).

Input

year: The year to check.

Output

Return true for a leap year and false otherwise.

सीमाएँ

1 ≤ year ≤ 9999.

उदाहरण

उदाहरण 1
इनपुट:
year = 2024

अपेक्षित आउटपुट:
expected = True
इनपुट:
long long year = 2024;

अपेक्षित आउटपुट:
bool expected = true;
इनपुट:
long year = 2024;

अपेक्षित आउटपुट:
bool expected = true;

व्याख्या

2024 is divisible by 4 and not by 100.

उदाहरण 2
इनपुट:
year = 2100

अपेक्षित आउटपुट:
expected = False
इनपुट:
long long year = 2100;

अपेक्षित आउटपुट:
bool expected = false;
इनपुट:
long year = 2100;

अपेक्षित आउटपुट:
bool expected = false;

व्याख्या

2100 is divisible by 100 but not by 400, so the century exception applies.

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Most years follow the divisible-by-4 rule, but centuries are exceptions.

संकेत 2

A year divisible by 400 is still a leap year, even though it is also divisible by 100.

संकेत 3

Check the exception before rejecting century years, or you may misclassify years like 2000.

अपेक्षित जटिलता

O(1) time, O(1) extra space

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।