Given a list of integers, return a list where each element at index i is the product of all elements in the input list except the element at index i. You must solve this without using division and in O(n) time complexity.
Examples:
Input: nums = [1, 2, 3, 4]
Output: [24, 12, 8, 6]
Explanation: For 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 = [2, 3]
Output: [3, 2]
Explanation: For index 0: 3, for index 1: 2
Input: nums = [-1, 1, 0, -3, 3]
Output: [0, 0, 9, 0, 0]
Explanation: Any product containing 0 results in 0
Input: nums = null
Output: null
Explanation: Null input returns null
Input: nums = []
Output: []
Explanation: Empty list 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 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.