Solution to Max-Profit by codility

25 Jan

Question: http://codility.com/demo/take-sample-test/max_profit

Question Name: MaxProfit

For this question, we have to travel from the last element to the first one.

18 thoughts on “Solution to Max-Profit by codility

  1. Hi Sheng, Thank you so much for sharing your solution! Can you please help me… I am trying to find the start and end index of the maximum-sum-subarray in your solution above. Can you please guide me?

    • You need to add two variables (for begin and end index) and re-write the code in line 14 and 15. If you really understand the solution, it is a easy job.

  2. Here is my solution. Python 100/100.

  3. C solution, I got 100%

  4. My solution in JAVA

  5. I have solved the problem with the following:

    However I must admit that this does not work IF the cheapest price is in “the last day”.

    • I cannot agree with you. It’s apparently wrong. Maybe the code is incomplete and you should read the guildlines before posting the code 🙂

  6. 100%, 100% Java solution

  7. JS 100% with another point of view

Leave a Reply

Your email address will not be published. Required fields are marked *