Interview Question
Share Lesson

Product Array

Given an array of integers, write a function buildProductArray that returns an array where each item is the product of all the items in the input array except for the item at that index.

Constraints:

  1. Solve this without using division
  2. You can create a results array, and it won't count against your space complexity
  3. Memory may be a concern though, so try to limit your use of additional data structures
 

Breakdown

Loading...
Follow teacher
Share:

Table of Contents

Validate My Answer

  1. You may immediately recognize a brute force O(n2) answer. You can get this down to O(n).

  2. You may want to add additional arrays to get the O(n) time complexity. However, you can solve this without any additional data structures other than your results array.

  3. To get it to O(n) without additional arrays, you may have to perform sequential O(n) time complexity operations.

  4. Does your solution handle 0 or negative numbers?

Loading...
Follow teacher
Share:

Table of Contents

Test Results

Run your code and see results here...

/**
 * @param {List [int]} input
 * @return {List [int]}
 */
const buildProductArray = (input) => {
  // Your solution here
};
// Upgrade for full course access
// Upgrade for full course access

Product Array

Given an array of integers, write a function buildProductArray that returns an array where each item is the product of all the items in the input array except for the item at that index.

Constraints:

  1. Solve this without using division
  2. You can create a results array, and it won't count against your space complexity
  3. Memory may be a concern though, so try to limit your use of additional data structures
 
/**
 * @param {List [int]} input
 * @return {List [int]}
 */
const buildProductArray = (input) => {
  // Your solution here
};
// Upgrade for full course access
// Upgrade for full course access