To the Top
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 | 184 Views, 13222 Search Bots | 92 Words

Subscribe to Feed Burner | 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:


def buy_and_sell(arr):
#Fill this in.

print buy_and_sell([9, 11, 8, 5, 7, 10])
# 5
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 184 Views, 13222 Search Bots | 92 Words Subscribe to Feed Burner

Related Articles

  1. Find Missing Numbers in an Array
  2. YES!!
  3. [Daily Problem] Longest Palindromic Substring
  4. Longest Substring Without Repeating Characters
  5. [Daily Problem] Validate Balanced Parentheses
  6. Top K Frequent words
  7. Consecutive Ones
  8. Daily Interview Question: Word Search
  9. Daily Interview Problem:Create a balanced binary search tree
  10. Daily Interview Problem: Minimum Removals for Valid Parenthesis

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />