Menu
Coddy logo textTech

Product Array Except Self

Lesson 2 of 3 in Coddy's Interview Coding Challenges - Pack IX course.

challenge icon

Challenge

Medium

Write a function named productExceptSelf that, given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

For example,

Input: [1,2,3,4]
Output: [24,12,8,6]

Constraints:

  • It's guaranteed that the product of the elements of any prefix or suffix of the array (including the whole array) fits in a 32-bit integer.
  • Solve it without using division and in O(n).

Try it yourself

int* productExceptSelf(int* nums, int numsSize, int* returnSize) {
    // Write code here
}

All lessons in Interview Coding Challenges - Pack IX

1Challenges

Rotate ArrayProduct Array Except SelfMaximum Sum Circular Subarray