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!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

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 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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In