<jupyter_start><jupyter_text>Maximum Profit From Stocks[The Original Question](https://mp.weixin.qq.com/s/JgCBBcm4E_wMUba5cXI9kg)  QuestionYou are given an array. Each element represents the price of a stock on that particular day. Calculate and return the maximum profit you can make from buying and selling that stock only once.  Example```python3[9, 11, 8, 5, 7, 10]```Here, the optimal trade is to buy when the price is `5`, and sell when it is `10`, so the return value should be $10 - 5 = 5$.<jupyter_code>def buy_and_sell(array: list) -> int:
    max_prof = i = 0
    j = 1
    while i < len(array) and j < len(array):
        if array[j] > array[j - 1]:
            max_prof = max(array[j] - array[i], max_prof)
            j += 1
            pass
        else:
            i = j
            j += 1
            pass
        pass
    return max_prof
print(buy_and_sell([9, 11, 8, 5, 7, 10]))<jupyter_output>5
{'fraction_non_alphanumeric': 0.10601092896174863, 'fraction_numerical': 0.036065573770491806, 'mean_word_length': 2.578125, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '49664', 'license': 'MIT', 'n_tokens_mistral': 335, 'n_tokens_neox': 302, 'n_words': 112, 'path': 'February/Week5/34.ipynb', 'repo_name': 'Dragon1573/Daily-Problem', 'size': '915'}