java implementation of stock buy sell problem
public int largestProfit(int[] prices) {
int profit = 0;
int min = Integer.MAX_VALUE;
for(int i = 0; i < prices.length; i++) {
if (prices[i] > min) {
profit = Math.max(profit, prices[i] - min);
} else {
min = prices[i];
}
}
return profit;
}