Minimum money needed

i am getting wrong ans on submisson

@royprincejmp
It seems that you have fixed your mistake and have scored 100 points in the question.
Do you have any doubt now?

ye please tell the mistake on prev approach

the size of prev was n, it should be w