For [1,2,3,4] style array length 6, print products without division.
| Test | Status | Details |
|---|
Ready — edit the code above and click Run or Submit.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] a = { 1, 2, 3, 4, 5, 6 };
int len = a.Length;
int[] outArr = new int[len];
outArr[0] = 1;
for (int j = 1; j < len; j++) outArr[j] = outArr[j - 1] * a[j - 1];
int suffix = 1;
for (int j = len - 1; j >= 0; j--) { outArr[j] *= suffix; suffix *= a[j]; }
Console.WriteLine(string.Join(" ", outArr));
}
}
Try solving on your own first, then reveal the official answer.
Prefix + suffix products.