Finding Minimum and Maximum in an Array
Source: Dev.to
Problem Statement
Given an array of numbers, we need to find the smallest (minimum) and largest (maximum) elements.
Example
Input: [1, 4, 3, 5, 8, 6]
Output: [1, 8]
Approach
Use Python’s built‑in functions:
min()to find the smallest elementmax()to find the largest element
This approach is simple and efficient.
Code
def find_min_max(arr):
return [min(arr), max(arr)]
Explanation
The function takes an array as input and returns a list containing the minimum and maximum values using the built‑in min and max functions.
Time Complexity
O(n) – each element is examined once to determine the minimum and maximum.