In all DP problems you have taken best=-1 the comparing max of best and ans and returning I didn’t get this logic please help.
What is the motto behind taking best=-1
@rssrivastavarohan
Hello Rohan,
In this problem we want to find longest increasing subsequence right?
so what can be possible answers it might 1or 2 or 3 or any other bigger number (minimum answer will be always greater than or equal to 1)
So Intially we put -1(can put 0 or any other negative number as well) in best becuase on taking best=max(best,answer) best value will change for sure(as answer will be atleast 1)
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.