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.
My Python3 solution following @rdgpcampos explanation. Please see @rdgpcampos for their thorough and clear explanation.
I Used p to keep track of Permutations , c for Correct Cases and tl for Total cases.
Overall the solution is same as the one shown by @rdgpcampos.
And the main Function that is Mandatory to finish in time is the pow() function.
deflegoBlocks(n,m):# Write your code herep=[0,1,2,4,8]+[-1forxinrange(m)]c=[0,1]+[-1forxinrange(m)]tl=[0,1]+[-1forxinrange(m+5)]foriinrange(5,m+1):p[i]=p[i-1]+p[i-2]+p[i-3]+p[i-4]tl[i]=pow(p[i],n,1000000007)foriinrange(2,5):tl[i]=pow(p[i],n,1000000007)foriinrange(2,m+1):c[i]=tl[i]forjinrange(i):c[i]-=c[j]*tl[i-j]c[i]=c[i]%(1000000007)returnc[m]
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 →
My Python3 solution following @rdgpcampos explanation. Please see @rdgpcampos for their thorough and clear explanation. I Used p to keep track of Permutations , c for Correct Cases and tl for Total cases. Overall the solution is same as the one shown by @rdgpcampos. And the main Function that is Mandatory to finish in time is the pow() function.