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

Smallest of Three

Return the smallest of three integers.

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

  • Keep track of the best value so far
  • Compare values with if statements
  • Handle ties and negative numbers

समस्या

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

Three friends compare how many minutes they were late this week and the one who was late the least gets to pick lunch. Given the three numbers, find the smallest. Some values can be equal, and they can be negative (early).

Implement smallest_of_three(a, b, c).

Input

a: The first number.

b: The second number.

c: The third number.

Output

Return the smallest of the three values. If several are equal and smallest, return that value.

सीमाएँ

−10^18 ≤ a, b, c ≤ 10^18

उदाहरण

उदाहरण 1
इनपुट:
a = 7
b = 15
c = 3

अपेक्षित आउटपुट:
expected = 3
इनपुट:
long long a = 7;
long long b = 15;
long long c = 3;

अपेक्षित आउटपुट:
long long expected = 3;
इनपुट:
long a = 7;
long b = 15;
long c = 3;

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

व्याख्या

3 is less than both 7 and 15.

उदाहरण 2
इनपुट:
a = -4
b = -4
c = 10

अपेक्षित आउटपुट:
expected = -4
इनपुट:
long long a = -4;
long long b = -4;
long long c = 10;

अपेक्षित आउटपुट:
long long expected = -4;
इनपुट:
long a = -4;
long b = -4;
long c = 10;

अपेक्षित आउटपुट:
long expected = -4;

व्याख्या

The two −4 values tie for smallest, so the answer is −4.

कैसे हल करें

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

संकेत 1

Assume the first number is the smallest.

संकेत 2

Compare it with the second and then the third, updating when you find a smaller one.

संकेत 3

Use a 64-bit integer type, the values can be very large.

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

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

संदर्भ

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

हर कोडर का सबसे अच्छा पास हुआ समाधान। तेज़, कम मेमोरी वाले और बेहतर रेटिंग वाले समाधान ऊपर रहते हैं।

अभी कोई पास हुआ समाधान नहीं है। इसे हल करें और पहला स्थान पाएँ।

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

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

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