Загрузка страницы

Leetcode 309. Best Time to Buy and Sell Stock with Cooldown [ Algorithm + Code Explained]

One of the most frequently asked coding interview questions on Array in companies like Google, Facebook, Amazon, LinkedIn, Fintech firm like Morgan Stanley, Goldman, J P Morgan, Microsoft, Uber, Apple, Adobe etc.

LeetCode : Best Time to Buy and Sell Stock with Cooldown

Problem URL - https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/

Time complexity - O(n)
Space Complexity - 0(n)
**Here we are using 2D array (row = no. of elements in given array i.e n , column = 2 ) . So we can treat space complexity it as O(n).**

Question :Say you have an array for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions:

You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
After you sell your stock, you cannot buy stock on next day. (ie, cooldown 1 day)

Example:

Input: [1,2,3,0,2]
Output: 3
Explanation: transactions = [buy, sell, cooldown, buy, sell]

Connect with me on LinkedIn at: https://www.linkedin.com/in/jayati-tiwari/

Видео Leetcode 309. Best Time to Buy and Sell Stock with Cooldown [ Algorithm + Code Explained] канала jayati tiwari
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
2 июня 2020 г. 18:33:50
00:14:55
Яндекс.Метрика