Stock Maximize Discussions | | HackerRank

Stock Maximize

  • + 0 comments
    public static long stockmax(List<int> prices)
    {
        var profit = 0L;
        var max = prices.Count()-1;
        while(max > 0){
            var i = max-1;
            while(i >= 0 && prices[i] <= prices[max]){
                profit += prices[max] - prices[i];
                i--;
            }
            max = i;
        }
        return profit;
    }