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.
- Lego Blocks
- Discussions
Lego Blocks
Lego Blocks
Sort by
recency
|
83 Discussions
|
Please Login in order to post a comment
Having some difficult with a valid JavaScript version. The values that are failing are when combinations get over MOD (10^9 +7) Has anybody got a JavaScript version working or can spot the error in this code? Thanks
*(legoBlocks(8,10) on my code is giving 634608018.
Hacker rank is giving 634597424*
}
This question wrinkled my brain until I looked at Willis42's code. Here's some extra annotation in case it helps.
def legoBlocks(n, m): # the ways to build a line of m from 0 up to 4 using legobricks from 1-4 # this takes the prev sums and adds one more way to it each time permutations = [0, 1, 2, 4, 8] mod = 10**9+7 # just keeps our numbers from getting too large - wraps if so
Main points to take care about are: 1) calculate total number of combination per row using dynamic programming 2) inclusion/exclusion concept by splitting the wall on 2 parts - use dynamic programming for better performance 3) Fast/binary exponentiation by squaring the base and halving the exponent
Java code
Anyone know how I can improve my score (83.33) to 100.00. I've done all the optimisations I could think of..
class Result {
}
this question would be Hard Level in Leetcode