Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[1 kyu] Faberge easter eggs crush test [linear]
#1
Hello everyone,

This is the SUPER performance version of This kata.

Kata available here

So far I've managed to solve the previous kata in JS keeping the maximum value under 800ms. I'll post my code here 

Code:
function height(n, m) {
 if (n===m){
 return (2**m)-1;
 }
 if (n == 0 || m == 0) {
   return 0;
 }
 if (m === 1) {
   return 1;
 }
 if (n === 1) {
   return m;
 }
 var res = new BigNumber(0);
 var s = new BigNumber(1);
 for (let k = 1; k <= n; k++) {
     s = s.mul(m - k + 1).div(k);
     res = res.add(s);
   }
   return res;
}

This is a really hard task if you know how to improve my code let me know
Code:
{
 "name" : "Federico",
 "version" : "2.0",
 "Age" : "23",
 "description" : "Ambitious and eclectic person"
}

  


Forum Jump:


Users browsing this thread:
1 Guest(s)