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
Lego Blocks
Sort by
recency
|
70 Discussions
|
Please Login in order to post a comment
O(n * m^2), strange this passed, since it requires at least 1 billion operations. can be modified to O(t*n*m) by calculating each height individually in response to the query, instead of calculating all 1 <= n <= 1000
there's probably a O(n* m) algo by finding a constant time method to calculate the number of bad layouts of length m+1 from smaller length bad layouts, but this O(n* m^2) algo already pass all tests so i cant be bothered
I've found a good solution here. There are solutions written in Python, Java, C++, and C.
I reformatted the Java code to make easier to understand:
Here is my solution in java, javascript, python, C ,C++, Csharp HackerRank Lego Blocks Problem Solution
Here is the solution of Lego Blocks Click Here
I got stucked in a corner case, and then in a corner case of that case. It's easy to overlook when you have abstracted the problem. Thinking in "Lego", blocks only stick together vertically. If your wall has just one row those blocks are free from each other. Then:
1) (Almost) every wall of height 1 is going to be non-solid (answer = 0).
2) Unless... it consist of just one piece (answer = 1).