Given a list of integers, return a new list where each element at index i is the product of all elements in the original list except the one at index i. Do not use division. Return an empty list for null or empty input.

Examples:

Input: nums = (1, 2, 3, 4) Output: (24, 12, 8, 6) Explanation: Index 0 = 2*3*4=24, Index 1 = 1*3*4=12, Index 2 = 1*2*4=8, Index 3 = 1*2*3=6 Input: nums = (0, 1, 2, 3) Output: (6, 0, 0, 0) Explanation: Index 0 = 1*2*3=6, others include 0 so product is 0 Input: nums = (3, 5) Output: (5, 3) Explanation: Each element is the other element Input: nums = (7) Output: (1) Explanation: No other elements, product is 1 Input: nums = null Output: () Explanation: Null input returns empty list
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 September 2026 (Sep 1–15)Sponsored by FLXBL

Contest runs September 1 - 15. Complete challenges to climb the leaderboard!

1st & 2nd: Salesforce certification exam voucher see all prizes

Only the 15 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