You are viewing a single comment's thread. Return to all comments →
I convert them to string and calculate the multiply with this function:
function strMultiply(a,b){ const strA = String(a).split("").reverse().join(''); //i const strB = String(b).split("").reverse().join(''); // j const result = new Array(strA.length + strB.length).fill(0); for(let i=0 ;i<strA.length;i++){ for(let j=0;j<strB.length;j++){ const mult = +strA[i] * +strB[j]; const sum = result[i+j] + mult result[i+j] = sum % 10; result[i+j + 1] += Math.floor(sum/10) } } while(result[result.length -1]===0){ result.pop() } return result.reverse().join("") }
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Extra Long Factorials
You are viewing a single comment's thread. Return to all comments →
I convert them to string and calculate the multiply with this function: