You are viewing a single comment's thread. Return to all comments →
Javascript
function kFactorization(n, A) { // Write your code here A.sort((a,b)=>a-b); function result(e,f,A){ if (e==1){ f.push(1); return f; } if (A.length==0){ return [-1]; } if (e % A[A.length -1]==0){ f.push(e); e = e / A[A.length -1]; } else{ A.pop(); } return result(e,f,A); } let res = []; res = result(n,[],A); res.sort((a,b)=>a-b); // console.log(res); return res; }
Seems like cookies are disabled on this browser, please enable them to open this website
K Factorization
You are viewing a single comment's thread. Return to all comments →
Javascript