Back to articles
Finding Minimum and Maximum in an Array

Finding Minimum and Maximum in an Array

via Dev.to TutorialSandhya Steffy M

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.

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles