DEV Community

Discussion on: Daily Coding Problem #2

Collapse
 
nataz77 profile image
Simone Natalini

Don't know if the use of Parallel.ForEach is legit, but here's my take using C# and Linq

static void DoWork(int[] original)
{
   var res = new int[original.Length];
   for (int i = 0; i < original.Count(); i++)
   {
      var notCurrent = original.Where(x => x != original[i]);
      int sum = 1;
      Parallel.ForEach(notCurrent, (notI)=>{ sum = sum*notI;});
      res[i]= sum;
    }
}