समस्या
Walk through the list once and track both the smallest and the largest value.
Implement min_and_max(numbers).
Input
numbers: A non-empty list of integers.
Output
Return [smallest, largest].
सीमाएँ
1 ≤ length ≤ 100,000
उदाहरण
उदाहरण 1
इनपुट:
numbers = [4, -2, 9, 0]
अपेक्षित आउटपुट:
expected = [-2, 9]
इनपुट:
std::vector<long long> numbers = {4, -2, 9, 0};
अपेक्षित आउटपुट:
std::vector<long long> expected = {-2, 9};
इनपुट:
long[] numbers = new long[] {4, -2, 9, 0};
अपेक्षित आउटपुट:
long[] expected = new long[] {-2, 9};
व्याख्या
The smallest value is -2 and the largest is 9: [-2, 9].
उदाहरण 2
इनपुट:
numbers = [7]
अपेक्षित आउटपुट:
expected = [7, 7]
इनपुट:
std::vector<long long> numbers = {7};
अपेक्षित आउटपुट:
std::vector<long long> expected = {7, 7};
इनपुट:
long[] numbers = new long[] {7};
अपेक्षित आउटपुट:
long[] expected = new long[] {7, 7};
व्याख्या
With one value it is both the smallest and largest: [7, 7].
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।