Given an integer array, write a program that returns an array with elements = product of the integers in input array except the one in its position. Ex: Given input: [2, 3, 10, 4, 5], output: [600, 400, 120, 300, 240] What is the complexity of your program? When will your program not work? Below is what I presented (O(n)), but it did not qualify me for the next round.
Anonym
public int product(List input) { int product = 1; foreach(int i in input) { product = product * i; } return product; } public void printOutput(List input) { foreach(int i in input) Console.WriteLine(i); } public List multiply(List input) { List output = new List{}; int total_product = product(input); foreach(int i in input) { output.Add(total_product/i); } return output; } public void main() { List input = new List{"2","3","10","4","5"}; printOutput(multiply(input)); Console.ReadLine(); }