You are given the prices of stock for n number of days. every ith day tell the price of the stock on that day. find the maximum profit that you can make by buying and selling stock with the restriction of  After you sell your stock, you cannot buy stock on the next day (i.e., cooldown one day).
Example:
Input:
5
1 2 3 0 2
Output:
3
Explanation:
You buy on 1st day and sell on the second day then cooldown, then buy on the fourth day and
sell on the fifth day and earn a profit of 3.
Your Task:
You don't have to read input or print anything. Your task is to complete the function maximumProfit() which takes the integer n and array prices and returns the maximum profit that can earn.
Expected Time Complexity: O(n)
Expected Space Complexity: O(n)
Constraint:
1<=n<=10^{5}
1<=prices[i]<=10^{5}

Source: geeksforgeeks | Difficulty: MEDIUM

Starter code: #User function Template for python3



class Solution:

    def maximumProfit(self, prices, n):

        #Code here

Solutions:
class Solution:

	def maximumProfit(self, prices, n):
		n = len(prices)
		dp = [[0 for x in range(2)] for y in range(n + 2)]
		dp[n][0] = dp[n][1] = 0
		for i in range(n - 1, -1, -1):
			for j in range(2):
				profit = 0
				if j:
					profit = max(-prices[i] + dp[i + 1][0], 0 + dp[i + 1][1])
				else:
					profit = max(prices[i] + dp[i + 2][1], 0 + dp[i + 1][0])
				dp[i][j] = profit
		return dp[0][1]


class Solution:

	def maximumProfit(self, prices, n):
		if n < 2:
			return 0
		dp = [[0 for _ in range(n)] for _ in range(2)]
		dp[1][0] = -prices[0]
		dp[0][1] = 0 if prices[1] < prices[0] else prices[1] - prices[0]
		dp[1][1] = max(dp[1][0], -prices[1])
		for i in range(2, n):
			dp[0][i] = max(dp[1][i - 1] + prices[i], dp[0][i - 1])
			dp[1][i] = max(dp[0][i - 2] - prices[i], dp[1][i - 1])
		return dp[0][n - 1]


class Solution:

	def maximumProfit(self, prices, n):
		dp = [[0 for i in range(2)] for j in range(n + 2)]
		dp[n][0] = dp[n][1] = 0
		for ind in range(n - 1, -1, -1):
			dp[ind][1] = max(-prices[ind] + dp[ind + 1][0], dp[ind + 1][1])
			dp[ind][0] = max(prices[ind] + dp[ind + 2][1], dp[ind + 1][0])
		return dp[0][1]


class Solution:

	def maximumProfit(self, prices, n):
		dp = [[0 for i in range(2)] for j in range(n + 2)]
		dp[n][0] = dp[n][1] = 0
		for ind in range(n - 1, -1, -1):
			for buy in range(2):
				if buy:
					profit = max(-prices[ind] + dp[ind + 1][0], dp[ind + 1][1])
				else:
					profit = max(prices[ind] + dp[ind + 2][1], dp[ind + 1][0])
				dp[ind][buy] = profit
		return dp[0][1]