Friends Pairing Problem

Not sure what is wrong with the code.
Link : https://ide.codingblocks.com/s/176008

Hey @Codemaniac_Aditya as the result can become large please make sure that your function returns long long instead of int and your dp array is also long long.

Yes! Thanks, it, worked however how to get whether the values are going to be in long long range!

Since in this problem dp[i] is a * dp[i-2] + dp[i-1], a being constant that is greater than 1, you can see that values will grow exponentially. Usually combination of constraints and dp state can tell if we will need long long or int. If you are unsure you can always iterate over the entire dp array and make sure dp[i] is always greater than dp[ i - 1] ( because monotonic increase with n) if dp[i] is smaller than dp[i-1] you can quite confidently say that integer overflow must have caused that.
I hope your doubt is clear now, if so please mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.