Member-only story

Product of Array Except Self — Grasp the Pattern for Array-based Problems (Coding Interview)

Ganesh Prasad
4 min readJul 17, 2021

--

the array of all products of all elements except self

This is a medium category array-based problem and has been asked by Facebook, Lyft, amazon, apple, Microsoft, Asana, adobe, Uber, and Oracle.

This problem is part of the 30 days preparation plan for coding interviews.

Most likely you will be asked to solve this problem in linear time and without using division 😌.

Description

You are given an array of size n, you have to produce an array where each element at index i is the product of all the other elements of the input array except the ith element

Input: 1 2 3 4 5
Output: 120 60 40 30 24
Explanation: 120 = 2 x 3 x 4 x 5
60 = 1 x 3 x 4 x 5
40 = 1 x 2 x 4 x 5
...

Do you want to stay updated on Coding interview tips and new Questions? Please click on subscribe button to get an email when the new tutorial is published.

Approach 1: Brute force 🙄

--

--

Ganesh Prasad
Ganesh Prasad

Written by Ganesh Prasad

Backend Developer at Appscrip | C++ veteran, 💜 Dart

No responses yet