Learn
Exam

Minimum and Maximum of a Two-Dimensional Array

Difficulty
BEGINNER

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 (n and m) are between 1 and 20 inclusive. n and m can 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]]:
    1. The smallest value is 1 and the largest value is 15.
    2. The function returns [1, 15].

Explanation for Test Case 2

  • When numbers = [[100, 200], [300, 400], [500, 600]]:
    1. The smallest value is 100 and the largest value is 600.
    2. The function returns [100, 600].

Explanation for Test Case 3

  • When numbers = [[1]]:
    1. The only element in the array is 1, so both the smallest and largest values are 1.
    2. The function returns [1, 1].