filmov
tv
LeetCode 121. Best Time to Buy and Sell Stock [Algorithm + Code Explained ]
Показать описание
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.
LeetCode : Best Time to Buy and Sell Stock
Question : Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
Example 1:
Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Not 7-1 = 6, as selling price needs to be larger than buying price.
Example 2:
Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
LeetCode : Best Time to Buy and Sell Stock
Question : Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
Example 1:
Input: [7,1,5,3,6,4]
Output: 5
Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.
Not 7-1 = 6, as selling price needs to be larger than buying price.
Example 2:
Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
Sliding Window: Best Time to Buy and Sell Stock - Leetcode 121 - Python
LeetCode Solution - 121 Best time to Buy and Sell Stock | Javascript
121. Best Time to Buy and Sell Stock - Leetcode - Python 3 - Brute Force and Two Pointer Solution
LeetCode Best Time to Buy and Sell Stock Solution Explained - Java
Best Time to Buy and Sell Stock - LeetCode 121 - Java
LeetCode 121. Best Time to Buy and Sell Stock [Algorithm + Code Explained ]
Best Time To Buy And Sell Stock - 121. LeetCode - Java
Best Time to Buy and Sell Stock - Leetcode 121 - Arrays & Strings (Python)
LeetCode 121 | Best Time to Buy and Sell Stock | Solution Explained in Java
LeetCode 121 Best Time to Buy and Sell Stock in javascript
LeetCode #:121 Best Time to Buy and Sell Stock
Best Time To Buy & Sell Stock 1 (LeetCode 121) | Full solution with visuals and animation
[Java] Leetcode 121. Best Time to Buy and Sell Stock [DP Decision Making #1]
LEETCODE 121 (JAVASCRIPT) | BEST TIME TO BUY AND SELL STOCK
121. Best Time to Buy and Sell Stock - LeetCode Javascript
Best time to buy and sell stock to Maximise Profit Leetcode - 121 | Java and C++ | DSAOne Course #14
LeetCode Problem: 121. Best Time to Buy and Sell Stock | Java Solution
Leetcode#121: Best Time to Buy and Sell Stock - Swift (Swift Programming & Algorithms)
Leetcode 121 - Best Time to Buy and Sell Stock | Javascript - Top Interview 150
BEST TIME TO BUY AND SELL STOCK | LEETCODE # 121 | PYTHON SOLUTION
Amazon Interview Question Leetcode 121. Best Time to Buy and Sell Stock Python
Разбор задачи 121 leetcode.com Best Time to Buy and Sell Stock. Решение на C++
121. Best Time to Buy and Sell Stock | JavaScript | Two Pointers | LeetCode 75 | Daily Challenge
Leetcode | 121. Best Time to Buy and Sell Stock | Easy | Java Solution
Комментарии