Given an array of integers, return an array where each element at index i is the product of all the numbers in the input array except the number at index i.
Explanation: Step-by-step: Given the input [1, 2, 3, 4], we calculate the product of all numbers except the first number 1. The product of remaining elements is 2 * 3 * 4 = 24. Similarly, we calculate the product of all numbers except the second number 2, which is 1 * 3 * 4 = 12. We repeat this process for the third and fourth numbers, giving us the output [24, 12, 8, 24].
Explanation: Step-by-step: Given the input [5, 1, 1, 1], we calculate the product of all numbers except the first number 5. The product of remaining elements is 1 * 1 * 1 = 1. Since the product of remaining elements for each element separately is indeed 1, the output is [5, 5, 5, 5].
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak