i want to know how can i print the value of buy and sell whenever buy and sell is updated… help me
Best time to buy and sell stock
for (int i = 0; i < v.size(); i++)
{
for (int j = i+1; j < v.size(); j++)
{
int profit = v[j] - v[i];
if (profit > maxProfit)
{
maxProfit = profit;
}
}
}
In your code snippet above, you can see that if profit is getting larger than maxprofit, than means we have found a new buy/sell pair. So inside the if condition you can print buy as v[i] and sell as v[j]