We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/////////////// ignore above this line ////////////////////functionmain(){vart=parseInt(readLine());for(vara0=0;a0<t;a0++){varn_temp=readLine().split(' ');varn=parseInt(n_temp[0]);vark=parseInt(n_temp[1]);varnum=readLine();// <-- SOlution start -->letarr=[]for(i=0;i<n;i++){letnums=Array.from(num,(a,b)=>{while(b>=i&&b<i+k){// Mapping Array if Index of number is Higher or Equal to the current loop index and less than the sum of K and current loop indexreturna}}).filter((a)=>a!=undefined)// Exclude Undefinedif(nums.length==k)arr.push(nums.reduce((a,b)=>a*b,1))// Push Multiplied results if the array's length equals to K}console.log(arr.sort((a,b)=>a-b)[arr.length-1])// <-- SOlution End -->}}
Cookie support is required to access HackerRank
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 solution: