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.
functionlegoBlocks(n,m){// Write your code hereconstA=1000000007n;constr=newArray(m+1).fill(0n);consta=newArray(m+1).fill(0n);a[0]=1n;for(letj=1;j<=m;j++){a[j]+=(j-1>=0)?a[j-1]:0n;a[j]+=(j-2>=0)?a[j-2]:0n;a[j]+=(j-3>=0)?a[j-3]:0n;a[j]+=(j-4>=0)?a[j-4]:0n;}for(letj=1;j<=m;j++){constn1=a[j]%A;constsum=n1**BigInt(n);a[j]=sum%A;}r[1]=1n;for(letj=2;j<=m;j++){r[j]=a[j];for(letk=1;k<j;k++){constn1=r[k]*a[j-k];r[j]-=n1;}// ATTENTION! in javascript, when the left operand of bigint is negative// need to add +A to be positive, different from python for exampler[j]=r[j]%A+A;}returnr[m]%A;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lego Blocks
You are viewing a single comment's thread. Return to all comments →
in javascript: