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.
As others have been saying, the answer numerically should be (m+n-2) choose (m-1) (mod 10^9 + 7). Of course, the problem is the time limit, which you will see if you try this method. Here are the two insights that I needed to solve this:
since the answer is mod p, make your own factorial function that takes mod p for every successive multiplication
Use FLT and fast exponentiation mod p to divide by (m-1)! and (n-1)! instead of calculating them and then dividing
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Tracing
You are viewing a single comment's thread. Return to all comments →
As others have been saying, the answer numerically should be (m+n-2) choose (m-1) (mod 10^9 + 7). Of course, the problem is the time limit, which you will see if you try this method. Here are the two insights that I needed to solve this: