Hi , I came across this challenge in hackerrank , it is a bit challenging , and it fits to be a math problem in my opinion , so I wonder if we can solve it using a mathematical expression .
the problem : https://www.hackerrank.com/challenges/lego-blocks/problem
I figured out the solution for n>1 and m<=4 which is : ((2^n)-1)^(m-1)
but I want a general solution for any n and any m.
this is my method (I prefer solving it by your own , I am afraid you read my method and feel overwhelmed unless you are super intelligent you read people's mind and how they think )
I used this tree of possibilities :
I suppose we use just 1x1 lego , for n, m we have n stacks of lego and (m-1) vertical lines (vertical breaks between lego of 1x1) if we suppose that merge 2 adjancent lego can remove the break so we have (2^n) -1 possibility in the first straight line (we have 2 options leave the break or merge so 2^n , but we cannot leave the breaks to form a straight line so we remove this possibility ) .
using possibilities counting for the first condition , but the second condition of the problem is broken once m>4 , because there is a constraint is the tree of possibilities vertically (we cannot have a straight line between legos) and also horizontally (we have have limited option of merge block that I didn't hold accountable , cannot merge blocks to have more than 5 blocks included )