Given a list of n integers where every value is in the range 1 to n (inclusive), some numbers appear more than once and others are missing. Return a list of all integers in the range 1 to n that do NOT appear in the input, in ascending order. Return an empty list for null or empty input.

Examples:

Input: nums = [4,3,2,7,8,2,3,1] Output: [5,6] Explanation: n = 8; 5 and 6 do not appear in the list Input: nums = [1,1] Output: [2] Explanation: n = 2; 2 is missing because 1 appears twice Input: nums = [1,2,3] Output: [] Explanation: All values 1 to 3 are present, nothing is missing
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 4–15)Sponsored by FLXBL

Contest runs October 4 - 15. 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 12 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