<jupyter_start><jupyter_text>Time Complexity O(n)^2 Space Complexity 0(1)<jupyter_code>stocks=[7,1,5,2,4]
   
def buy_sell_once(s):
    maxprofit=0
    #first loop
    for i in range(len(s)-1):
        print("i {}".format(i))
        print("s[i] {}".format(s[i]))
        for j in range(i+1,len(s)):
            print("j {}".format(j))
            print("s[j] {}".format(s[j]))
            if s[j] - s[i] > maxprofit:
                maxprofit=s[j] - s[i]
    return maxprofit

m=buy_sell_once(stocks)
print(m)<jupyter_output>i 0
s[i] 7
j 1
s[j] 1
j 2
s[j] 5
j 3
s[j] 2
j 4
s[j] 4
i 1
s[i] 1
j 2
s[j] 5
j 3
s[j] 2
j 4
s[j] 4
i 2
s[i] 5
j 3
s[j] 2
j 4
s[j] 4
i 3
s[i] 2
j 4
s[j] 4
4<jupyter_text>Time Complexity O(n) Space Complexity 0(1)<jupyter_code>def buy_sell_once_ef(ls):
    max_profit=0
    min_price=ls[0]
    for price in range(len(ls)-1):
        min_price = min(min_price,ls[price])
        profit    = ls[price]-min_price
        max_profit=max(profit,max_profit)
    return max_profit
m=buy_sell_once_ef([5,10,10])
print(m)<jupyter_output>5
{'fraction_non_alphanumeric': 0.16524216524216523, 'fraction_numerical': 0.04843304843304843, 'mean_word_length': 2.9328358208955225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '115118', 'license': 'MIT', 'n_tokens_mistral': 536, 'n_tokens_neox': 490, 'n_words': 114, 'path': 'array_strings/ipynb/.ipynb_checkpoints/buy_sell_stock-checkpoint.ipynb', 'repo_name': 'PRkudupu/Algo-python', 'size': '1053'}