@sateeshkumar1872 please try for the Bottom Up DP approach, since the constraints are large.
@sateeshkumar1872 You can have a look at this code.