I tried to solve this problem with nested loop:

```
public int maxProfit(int[] prices) {
int max = 0;
for(int i = 0; i<prices.length; i++){
int buyprice = prices[i];//test the case where buyer buys on the i-th day
for (int j = i; j<prices.length; j++){
int sellprice = prices[j];// test the case where the buyer sells on either the current day or after
int profit = sellprice-buyprice;
if(profit>=max){
max= profit;
}
}
}
return max;
}
```

And yet what I got is TLE with test case [10000,9999,9998,9997,9996,9995,9994,9993,9992,9991,9990,9989,9988,9987....]

Can anyone give me a hint what went wrong? Thank you in advance!