The Code In Video Is gives error

The code discussed in this video of Buy and Sell -|| fails for 4 test cases out of 6, and give TLE error. Please check.

Hello @saksham_thukral, pls tell the code which you are submitting as because that code was correct. And just try to understand the idea what we need to do.

for(int i = 1; i < n; i++)
{
    ans += max(0,arr[i]-arr[i-1]);
}

This will also work. We just want to maximize the profit so just buy the product at cheaper and sell it at a higher price, this will always work as there is no limit on the no. of transactions.

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.