Loading
Loading
A crop scientist measures the yield multiplier of each field in a chain of greenhouses. For each greenhouse she needs the combined multiplier of every OTHER greenhouse — the product of all values except the one at that position.
Return an array where position i holds the product of every value except yields[i]. Division is not allowed: a single zero multiplier would make it undefined.
yields = [1, 2, 3, 4]index 02 × 3 × 4 = 24index 11 × 3 × 4 = 12index 21 × 2 × 4 = 8index 31 × 2 × 3 = 6[24, 12, 8, 6]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) excluding output space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Each entry is the product of the other three.
Example 2
Only the position holding the zero escapes it; everywhere else the product includes that zero.