Finding Minimum and Maximum in an Array

Published: (March 19, 2026 at 10:48 PM EDT)
1 min read
Source: Dev.to

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 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 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.

0 views
Back to Blog

Related posts

Read more »

Next Permutation

Problem Description The task is to compute the next permutation of a given array of numbers. A permutation is a rearrangement of the same elements, and the nex...