← All Problems⏱ 0:00
p-2004
Product of Array Except Self
Given an integer array nums, print an array where result[i] is the product of all elements except nums[i].
Input Format
Line 1: n Line 2: n space-separated integers
Output Format
Print n space-separated integers.
Constraints
- 2 <= n <= 450
- -30 <= nums[i] <= 30
- Use an O(n) approach without division for full credit
Examples
Input
4 1 2 3 4
Output
24 12 8 6
Explanation
Each index gets product of all other numbers.
Hints
Hint 1
Hint 2
Code
>
Input
Expected Output
24 12 8 6
Each index gets product of all other numbers.
Run uses the currently selected testcase. Submit always evaluates your code against the full hidden test suite from the database.