"""
Given a list of stock prices for n days, find the maximum profit with a single buy or sell activity.

Given a list of daily stock prices (integers for simplicity), return the buy and sell prices for making the maximum profit.

We need to maximize the single buy/sell profit. If we can’t make any profit, we’ll try to minimize the loss.

USE: Kadane's Algorithm

"""


def find_buy_sell_stock_prices(array):
    current_buy = array[0]
    global_sell = array[1]
    global_profit = global_sell - current_buy
    current_profit = float("-inf")

    for i in range(1, len(array)):
        current_profit = array[i] - current_buy

        if current_profit > global_profit:
            global_profit = current_profit
            global_sell = array[i]

        if current_buy > array[i]:
            current_buy = array[i]

    return global_sell - global_profit, global_sell
    # return -1, -1 #Return a tuple with (high, low) price values


"""
Write a function that takes in a non-empty array of integers and returns the maximum sum that can be obtained by summing
up all of the integers in a non-empty subarray of the input array. A subarray must only contain adjacent numbers.
"""


def kadanesAlgorithm(array):
    # thank you Kadane :)
    current_max = global_max = array[0]
    for num in array[1:]:  # already initalized on the first value
        current_max = max(num, current_max + num)
        global_max = max(global_max, current_max)
    return global_max
