A design tool stacks transforms, and each layer has a scale factor in factors. For a tooltip, you need, for each layer, the product of every other layer's factor.
Write scaleWithoutSelf(factors) that returns an array where item i is the product of all factors[j] with j !== i. Don't use division (factors can be 0), and aim for O(n) time.
Input: factors = [2,3,4] Output: [12,8,6]
3 * 4 = 12, 2 * 4 = 8, and 2 * 3 = 6.
Input: factors = [5,0,2] Output: [0,10,0]
Only the item at index 1 skips the 0, so only it is non-zero.
2 <= factors.length <= 10^5-30 <= factors[i] <= 30Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #42 Scale Factor Without Itself. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.