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 | 217 Views, 14309 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 | 217 Views, 14309 Search Bots | 92 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Product of Array Except Self
  2. Generate All IP Addresses
  3. Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
  4. Daily Interview Problem: Deepest Node in a Binary Tree
  5. Algorithm Interview: Determine If Linked List is Palindrome
  6. Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
  7. CVE-2015-8874 - cPanel EasyApache Vulnerabilities
  8. Most Frequent Subtree Sum
  9. Maximum In A Stack
  10. Algorithm Interview: Level Order Traversal of Binary Tree

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />