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!

How 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 October 2026 (Oct 16–31)Sponsored by FLXBL

Contest runs October 16 - 31. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 16 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In