Find the second smallest distinct integer in a list. If the list does not contain at least two distinct values, return null. Return null for null input as well.
Examples:
Input: nums = [3, 1, 4, 1, 5]
Output: 3
Explanation: Distinct values sorted are [1, 3, 4, 5]. The second smallest is 3
Input: nums = [5, 3]
Output: 5
Explanation: Two distinct values, second smallest is 5
Input: nums = [2, 2, 2]
Output: null
Explanation: Only one distinct value, no second smallest exists
Input: nums = [7]
Output: null
Explanation: Single element, no second smallest
Input: nums = null
Output: null
Explanation: Null input returns null
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 July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.