Stock Maximize Discussions | Algorithms | HackerRank

Sort by

recency

|

366 Discussions

|

  • + 0 comments
    import java.util.Scanner;
    
    public class Solution 
    {
        private Scanner in;
        
        
        public Solution()
        {
            in = new Scanner(System.in);
            
        }
        
        public void run()
        {
            int testCases = in.nextInt();
            for(int test=0; test<testCases; test++)
            {
                int n = in.nextInt();
                int[] arr = new int[n];
                int[] dp = new int[n];
                for(int i=0; i<n; i++)
                    arr[i] = in.nextInt();
                int max = arr[n-1];
                for(int i=n-1; i>=0; i--)
                {
                    max = (arr[i]>max)?arr[i]:max;
                    dp[i] = max;
                }
                long sum = 0;
                for(int i=0; i<n; i++)
                {
                    sum += (dp[i] - arr[i]);
                }
                System.out.println(sum);
            }
        }
        
        public static void main(String[] args)
        {
            Solution solution = new Solution();
            solution.run();
        }
    }
    
  • + 0 comments

    lol I overcomplicated this problem for some reason

  • + 0 comments

    Just go from end to beginning

    long stockmax(vector<int> p) {
        long ans = 0; int max_num = 0;
        for(int i = p.size() - 1; i >= 0; i--) 
        {
            max_num = max(max_num, p[i]);
            ans += max(0, max_num - p[i]);
        }
        return ans;
    }
    
  • + 2 comments

    Not a DP problem. Solution is just to iterate backwards. If our current price is greater than the max price, update the max price. If it is smaller, then there is profit to be made - and that profit is the difference between the current price and max price (as we would offload all shares on the max price day).

    def stockmax(prices):
        profit = 0
        maxPrice = 0
        for price in prices[::-1]:
            if price > maxPrice:
                maxPrice = price
            else:
                profit += maxPrice - price
        return profit
    
    • + 0 comments

      It looks great

    • + 1 comment

      Maximizing the potential of Uber stock involves a multifaceted approach that leverages the company’s strengths and addresses its challenges. Investors should focus on the company's diversified revenue streams, particularly the growing sectors of Uber Eats and Uber Freight, which contribute significantly to overall financial health. Additionally, Uber’s advancements in autonomous vehicle technology could revolutionize the ride-hailing industry, offering long-term cost reductions and margin improvements. Staying informed about regulatory changes and market dynamics is crucial, as these factors can impact stock performance. Strategic investments in emerging markets and continuous innovation will also play key roles in driving future growth, making Uber a compelling choice for investors aiming to maximize their returns in the evolving tech and transportation sectors.

      • + 0 comments

        Stock Maximize is a strategic approach aimed at maximizing profits through smart stock trading decisions. It involves buying stocks at the lowest possible prices and selling them at peak market values. To achieve this, investors must analyze market trends, historical data, and financial indicators to make informed decisions. Tools like technical analysis, fundamental analysis here https://zinseszinsrechners.de/, and algorithmic trading can be employed to identify the optimal times for buying and selling stocks.

  • + 0 comments

    Here is my solution in java, javascript, python, C , C++, Csharp HackerRank Stock Maximize Problem Solution