- list item Question in short is finding i and j, such that i <j and prices[j]-prices[i] is maximum

```
int maxProfit(vector<int>& prices) {
if(prices.size()>0){
int ans = 0 , minS = prices[0];
for(int i=1;i<prices.size();i++){
minS = min(minS,prices[i]);
ans = max(ans,prices[i]-minS);
}
return ans;
}
return 0;
}
```