O(n) with division, in C#
using System; using System.Collections.Generic; using System.Linq; namespace Daily_Coding_Problem_2 { public class Program { static void Main(string[] args) { var numbers = GetNumberList(); var ret = Problem2(numbers); foreach (var i in ret) { Console.WriteLine(i); } } public static IEnumerable<int> GetNumberList() { return Console.ReadLine() ? .Split(' ') .Select(int.Parse) .ToArray(); } public static IEnumerable<int> Problem2(IEnumerable<int> numbers) { var enumerable = numbers as int[] ?? numbers.ToArray(); var product = enumerable.Aggregate(1, (current, n) => current * n); return enumerable.Select(n => product / n).ToList(); } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
O(n) with division, in C#