Problem
Given a n x m two-dimensional array numbers containing natural numbers, write a function solution that returns the smallest and largest values in the array as a list. For example, given the two-dimensional array:
numbers = [
[3, 8, 15],
[7, 1, 9],
[4, 12, 10]
]
The smallest value is 1 and the largest value is 15. The function should return [1, 15].
Constraints
- The dimensions of
numbers(nandm) are between 1 and 20 inclusive.nandmcan be different. - Each element
numbers[i][j]is a natural number between 1 and 1,000 inclusive.
Test Case
| Test Case Number | numbers | return |
|---|---|---|
| 1 | [[3, 8, 15], [7, 1, 9], [4, 12, 10]] | [1, 15] |
| 2 | [[100, 200], [300, 400], [500, 600]] | [100, 600] |
| 3 | [[1]] | [1, 1] |
Explanation for Test Case 1
- When
numbers = [[3, 8, 15], [7, 1, 9], [4, 12, 10]]:- The smallest value is
1and the largest value is15. - The function returns
[1, 15].
- The smallest value is
Explanation for Test Case 2
- When
numbers = [[100, 200], [300, 400], [500, 600]]:- The smallest value is
100and the largest value is600. - The function returns
[100, 600].
- The smallest value is
Explanation for Test Case 3
- When
numbers = [[1]]:- The only element in the array is
1, so both the smallest and largest values are1. - The function returns
[1, 1].
- The only element in the array is