You are viewing a single comment's thread. Return to all comments →
Okay. I'm improving. This should have taken me atleast an hour. Done it in 20 mins. C# solution
private static int getProduct(int[] arr) { int product = 1; foreach(int x in arr) product *= x; return product; } public static void printAnswer(string num, int n, int k) { int highestProduct = 0; int c = n-k+1; //max combinations for(int i = 0; i < c; i++) { string newStr = num.Substring(i,k); int [] arr = newStr.Select(x => x - '0').ToArray(); int product = getProduct(arr); if(product > highestProduct) { highestProduct = product; } } Console.WriteLine(highestProduct); }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #8: Largest product in a series
You are viewing a single comment's thread. Return to all comments →
Okay. I'm improving. This should have taken me atleast an hour. Done it in 20 mins. C# solution