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!

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

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