Q: How many paths are there to go from (0,0,0) to (n,n,n)? i.e. walk in a certain direction by one step each time.
A: (3n)C(n)*(2n)C(n)*(n)C(n). In general, for k-dimensional space, the answer would be a product of k terms. Things to ponder:
Why combination, not permutation? -> There are 3n steps to walk in total, and there are 3 dimensions x, y and z. We see the steps, not the dimensions, as the space to pick from. For example, for n = 2, there are 6 steps to make, 1, 2, 3, 4, 5 and 6. We pick two from these to assign to the x-direction, and that's why the order is not important (assigning x-direction to positions 1,5 is the same as assigning x-direction to positions 5,1).
See here for more interview questions/brainteasers
No comments:
Post a Comment