public int[] multiply(int[] input) {
    if (input == null) {
      throw new IllegalArgumentException("You can't pass a null array as input.");
    }
    if (input.length == 0) {
      return input;
    }

    int[] front = new int[input.length];
    int[] rear = new int[input.length];
    int[] output = new int[input.length];

    front[0] = 1;
    rear[input.length - 1] = 1;
    for (int i = 1; i < input.length; i++) {
      front[i] = front[i - 1] * input[i - 1];
    }
    for (int i = input.length - 2; i >= 0; i--) {
      rear[i] = rear[i + 1] * input[i + 1];
    }
    for (int i = 0; i < input.length; i++) {
      output[i] = front[i] * rear[i];
    }
    return output;
  }
Iterative solution to solve this problem. The complexity order of this algorithm is O(N) time
and space terms where N is the number of elements in the input array.
src/main/java/com/github/pedrovgs/problem39/MultiplyArrayElements.java