Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Product Except Self

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

You are given an array of n integers. Create a new array where each element at index i equals the product of all numbers in the array except the number at index i.

Example

Input:

4 1 2 3 4

Output:

24 12 8 6

Constraints

n <= 20

Input Format

n, array

Output Format

Product array

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
4
1 2 3 4
24 12 8 6
Basic case.
Sample #2
Public sample
2
0 0
0 0
Zeros.
Sample #3
Public sample
5
2 3 1 4 5
60 40 120 30 24
Sample case with distinct positive integers.
Sample #4
Public sample
4
0 1 2 3
6 0 0 0
Single zero case - only position with zero gets product of others.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings