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.
deflegoBlocks(n,m):# Write your code hereM=1000000007a=[0,1,2,4,8]#a[i]isthenumberofallwallswithwidthiforjinrange(5,m+1):#thisformulaexecutesonlywhenwehavewidth5ormorea.append((a[j-1]+a[j-2]+a[j-3]+a[j-4])%M)foriinrange(m+1):#thiswillgiveusallthewallsforheightna[i]=pow(a[i],n,M)# let r[i] be the number of good layouts that have height n, and width ir=[a[i]foriinrange(m+1)]#startwithallofthemforiinrange(1,m+1):forjinrange(1,i):r[i]-=(r[j]*a[i-j])#subtractthenumberofbadlayouts,whentheFIRSTverticalbreakinthewallappearsatindexjr[i]=r[i]%M#makethecomputationseasierreturnr[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 →
Python solution with comments: