Arrays

Problem shape

Beginner
4
8
15
16
23
42
Core idea

Track the best value seen so far while scanning the array once.

Step 1 / 5
Problem shape
Current lesson

Find Minimum and Maximum Lab

Arrays Beginner

Find Minimum and Maximum

Welcome to the Find Minimum and Maximum algorithm lab. Track the best value seen so far while scanning the array once. Use it when: Use when you need smallest, largest, range, or best candidate in a collection. The time complexity is O(n), and the space complexity is O(1). The pseudocode is: best = a[0] for i from 1 to n - 1 if a[i] is better than best best = a[i] return best As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(n)

Space

O(1)

Pseudocode

best = a[0]
for i from 1 to n - 1
  if a[i] is better than best
    best = a[i]
return best
Open deeper structure lesson
1.0x