Dsa
Arrays
Easy
Product of Array Except Self
Given an array of integers, return an array where each element at index i is the product of all the numbers in the input array except the number at i. You must not use division, and you should solve it in O(n) time.
Input format:
- The first line contains an integer n (1 <= n <= 10^5), the number of elements in the array.
- The second line contains n space-separated integers (|a[i]| <= 1000), the elements of the array.
Output format:
- Output a single line of n space-separated integers, the result array.
Example:
Input:
5
1 2 3 4 5
Output:
120 60 40 30 24
Key concepts
arraysmathprefix-suffix
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now