Applovin Coding Interview / OA: Product of Array Except Self

15 Views
No Comments

Given an input array, return a result array where each element at index i is the product of all values in the input array except input[i].

Example input array:

{2, 4, 3, 5}

Example result array:

{60, 30, 40, 24}
  • 60 is the product of all values of the input array except 2.
  • 30 is the product of all values of the input array except 4.
  • 40 is the product of all values of the input array except 3.
  • 24 is the product of all values of the input array except 5.

This is the classic Product of Array Except Self problem. For each position, the output value is the product of all other elements in the array, as shown by {2, 4, 3, 5} -> {60, 30, 40, 24}. A standard solution uses prefix and suffix products to compute the left-side and right-side contributions for each index, avoiding division and achieving linear time complexity.

END
 0