You are viewing a single comment's thread. Return to all comments →
Javascript
function greatestProduct (n,k,num) { let product = 0; arrayOfEl = num.split(""); for (let i = 0; i <= n - k; i++) { const multiplication = arrayOfEl .slice(i, k + i) .reduce((acc, curr) => (acc *= curr)); if (multiplication > product) product = multiplication; } console.log(product); } function main() { var t = parseInt(readLine()); for(var a0 = 0; a0 < t; a0++){ var n_temp = readLine().split(' '); var n = parseInt(n_temp[0]); var k = parseInt(n_temp[1]); var num = readLine(); greatestProduct(n,k,num) }
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 →
Javascript