Design an algorithm to find the maximum profit of a stock buy and sell?
One approach to finding the maximum profit of a stock buy and sell is to use the following algorithm:

1. Initialize two variables, `maxProfit` to represent the maximum profit made so far, and `minPrice` to represent the lowest price seen so far. Set `maxProfit` to 0, and `minPrice` to the first stock price.

2. Iterate through the array of stock prices for each day from the second day onwards.

3. For the current day, calculate the potential profit by subtracting the `minPrice` from the current price.

4. Update the `maxProfit` value if the potential profit is greater than the current `maxProfit`.

5. Update the `minPrice` value if the current price is lower than the current `minPrice`.

6. Once the iteration is complete, return the `maxProfit` value.

This algorithm will keep track of the maximum profit made so far while also updating the minimum price. It ensures that the buy occurs before the sell, and it will always return the greatest profit possible. The time complexity of this algorithm is O(n), where n is the number of days for which stock prices are available.
Below is an instruction that describes a task, write a response that appropriately completes the request.

### Instruction:
Design an algorithm to find the maximum profit of a stock buy and sell?

### Response:
One approach to finding the maximum profit of a stock buy and sell is to use the following algorithm:

1. Initialize two variables, `maxProfit` to represent the maximum profit made so far, and `minPrice` to represent the lowest price seen so far. Set `maxProfit` to 0, and `minPrice` to the first stock price.

2. Iterate through the array of stock prices for each day from the second day onwards.

3. For the current day, calculate the potential profit by subtracting the `minPrice` from the current price.

4. Update the `maxProfit` value if the potential profit is greater than the current `maxProfit`.

5. Update the `minPrice` value if the current price is lower than the current `minPrice`.

6. Once the iteration is complete, return the `maxProfit` value.

This algorithm will keep track of the maximum profit made so far while also updating the minimum price. It ensures that the buy occurs before the sell, and it will always return the greatest profit possible. The time complexity of this algorithm is O(n), where n is the number of days for which stock prices are available.