File: root - text - article - 2019 - 11 - maximum-profit-from-stocks.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 491 Views, 18032 Search Bots | 92 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 491 Views, 18032 Search Bots | 92 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Apple:
You are given an array. Each element represents the price of a stock on that particular day. Calculate and return the maximum profit you can make from buying and selling that stock only once.
For example: [9, 11, 8, 5, 7, 10]
Here, the optimal trade is to buy when the price is 5, and sell when it is 10, so the return value should be 5 (profit = 10 - 5 = 5).
Here's your starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 491 Views, 18032 Search Bots | 92 Words You are given an array. Each element represents the price of a stock on that particular day. Calculate and return the maximum profit you can make from buying and selling that stock only once.
For example: [9, 11, 8, 5, 7, 10]
Here, the optimal trade is to buy when the price is 5, and sell when it is 10, so the return value should be 5 (profit = 10 - 5 = 5).
Here's your starting point:
def buy_and_sell(arr):
#Fill this in.
print buy_and_sell([9, 11, 8, 5, 7, 10])
# 5
Related Articles
- Daily Interview Problem: Look and Say Sequence
- YES!!
- Algorithm Interview: No Adjacent Repeating Characters
- Daily Interview Problem: Spiral Traversal of Grid
- Print a tree level-by-level, with line-breaks
- Daily Interview Problem: Product of Array Except Self
- Daily Interview Problem: Merge K Sorted Linked Lists
- Skip the readings, focus on problems. And use all the hints!
- Daily Interview Problem: Word Ordering in a Different Alphabetical Order
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
©2006~2024 SteakOverCooked - 0.01104 Seconds(s) - 1705.887 KB/s - 35 Online Memory: 493.5 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !