Can you tell me my mistake?

Hi Vageesha. there are 2 mistakes in ur code. first of all u have made a dp array of size n while should make it of size n+1. secondly make it long long int instead of int as for the given range of n (<=30) ans value will be quite large.
U can refer this code https://ide.codingblocks.com/s/578064

When there are no friends, then the number of ways should be considered as 0 or 1?

that would be 0. if there no friends only then no arrangement is possible.

Hope ur doubts are cleared now

sir, apart from the long long, I have made the corrections, but my top down method gives output 3 instead of 4 for input as 3


I have made the changes. in base case u had used (n==0 || n==1) i have changed it to for (n<=2) dp[n] = n.
as for n = 2 there are n possible arrangements(ie 2).
try submitting it now. it will get submitted successfully.

if ur doubt is cleared u can mark the doubt as resolved and give ur valuable feedback.

okay… thank u…can you tell me where to give feedback

I will just mark it as resolved. u would get a link here only

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.

1 Like