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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Best time to buy and sell stock with cooldown | Leetcode #309Best Time to Buy and Sell Stock with Cooldown | leetcode 309 | HindiHard Leetcode problem Move A Box To Target Location (with implementation)Leetcode 122. Best Time to Buy and Sell Stock II [ Algorithm + Code Explained]Best Time to Buy and Sell Stock with Cooldown | Live Coding with Explanation | Leetcode - 309Minimum Size Subarray Sum | Leetcode #209Best Time to Buy and Sell Stock with Cooldown - Leetcode 309 - PythonSliding Window Technique - Algorithmic Mental ModelsCoding Interview Question | Best time to Buy and Sell Stock | One, any number and max K TransactionsBest Time to Buy and Sell Stocks with Cool down - Infinite Transactions Dynamic ProgrammingNUMBER OF PROVINCES (Leetcode) - Code & WhiteboardLeetcode 714. Best Time to Buy and Sell Stock with Transaction Fee [ Algorithm + Code Explained]Word Break | Leet code 139 | Theory explained + Python codeAMAZON CODING INTERVIEW QUESTION - PARTITION LABELS (LeetCode)Pro vs. Hard Coding Interview Problem - LRU Cache (LeetCode Day 24)Combination Sum IV | Live Coding with Explanation | Leetcode - 377How to prepare for coding interviews using Leetcode? Why Leetcode is the bestFirst missing positive leetcode solutionLeetCode 56. Merge Intervals (Algorithm Explained)Leetcode 123. Best Time to Buy and Sell Stock III [ Algorithm + Code Explained]