Market Interception

The criminal syndicate is profiting from a volatile artifact trading market. Your mission is to determine the perfect time to buy low and sell high to intercept the syndicate's profits.

Input is denoted by a list of integers `prices`.

  • Each integer represents the price of the artifact on a given day.
  • Your task is to maximize profit by choosing one day to buy and one day to sell, ensuring the buying day comes before the selling day. If no profit can be made, return `0`. For example, given `prices = [7, 1, 5, 3, 6, 4]`, buy on day 2 (price = 1) and sell on day 5 (price = 6), yielding a profit of `6 - 1 = 5`.


Case 1

Input: prices = [10, 20, 5, 15, 7, 10, 22, 1, 12]


Case 2

Input: The input is too long! Download it here (space seperated).


Submit Here