Given a non-empty list of integers, return a new list containing exactly two elements: the minimum value at index 0 and the maximum value at index 1. Find both values in a single pass without sorting.
Examples:
Input: nums = [3, 1, 4, 1, 5, 9, 2, 6]
Output: [1, 9]
Explanation: Minimum is 1, maximum is 9
Input: nums = [5]
Output: [5, 5]
Explanation: Single element is both minimum and maximum
Input: nums = [-3, -1, -7, 0, 2]
Output: [-7, 2]
Explanation: Minimum is -7, maximum is 2
Input: nums = [10, 10, 10]
Output: [10, 10]
Explanation: All elements equal, both min and max are 10
Input: nums = [100, 50, 75, 25]
Output: [25, 100]
Explanation: Minimum is 25, maximum is 100
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay June 2026
Contest runs June 1 - 30. Complete challenges to climb the leaderboard!
Only the 30 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.