Given a list of integers, return a new list where each element at index i is the product of all elements from index 0 to index i in the original list. The result has the same length as the input. Return null for null input and an empty list for an empty input.
Examples:
Input: nums = [1, 2, 3, 4]
Output: [1, 2, 6, 24]
Explanation: The running products are 1, 1 times 2, 1 times 2 times 3, and 1 times 2 times 3 times 4
Input: nums = [5]
Output: [5]
Explanation: Single element list returns itself
Input: nums = [2, 3, 0, 5]
Output: [2, 6, 0, 0]
Explanation: Once a zero appears, every subsequent running product is zero
Input: nums = []
Output: []
Explanation: Empty list returns empty list
Input: nums = null
Output: null
Explanation: Null input returns null
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.