import java.util.*;

public class Solution {
    public int maxProfit (int[] prices) {
      int min = Integer.MAX_VALUE;
      int maxProfit = 0;
      
      for (int p : prices) {
        maxProfit = Math.max(maxProfit, p - min);
        min = Math.min(p, min);
      }
      
      return maxProfit;
    }
}