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

🏆 All Time Leaderboard

Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In