Все задачи
Легко Решено: 0 Процент решений: 0%

Min and Max Together

Find the smallest and largest value in one pass.

Условие

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. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.