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:
To solve this problem, we can use Pythonโs built-in functions:
- min() to find the smallest element
- max() 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 the minimum and maximum values using built-in functions.
Time Complexity:
O(n) โ We need to check all elements.
Top comments (0)