Problem Statement
Given an array, find:
The minimum element
The maximum element
Example:
Input: [1, 4, 3, 8, 6]
Output: [1, 8]
Approach
You only need one loop.
Idea:
Assume first element is both min and max
Traverse the array
Update values when needed
Step-by-Step Example
Input:
[1, 4, 3, 8, 6]
Process:
Start → min = 1, max = 1
4 → max = 4
3 → no change
8 → max = 8
6 → no change
Final:
[1, 8]


Top comments (0)