Fetching latest headlines…
Min and Max Elements.
NORTH AMERICA
πŸ‡ΊπŸ‡Έ United Statesβ€’March 22, 2026

Min and Max Elements.

1 views0 likes0 comments
Originally published byDev.to

One way is to traverse the array and keep updating the min and max elements .

  1. initialize min = arr[0] max = arr[o]
  2. traverse the array from index 1

  3. For each element:
    If element < min β†’ update min
    If element > max β†’ update max

4.return max and min array
5.Time Complexity: O(n)
We traverse the array once
Space Complexity: O(1)

Comments (0)

Sign in to join the discussion

Be the first to comment!