Codility - MaxProfit

RESULT

import java.util.*;

class Solution {
    public int solution(int[] A) {
        int maxProfit = 0;
        int minShareSlice = Integer.MAX_VALUE;

        for (int i=0; i<A.length; i++) {
            minShareSlice = Math.min(minShareSlice, A[i]);
            maxProfit = Math.max(maxProfit, A[i] - minShareSlice);
        }

        return maxProfit;
    }
}