6 kyu

Most profit from stock quotes

465 of 1,175arhigod

Description:

 Return the most profit from stock quotes.

 Stock quotes are stored in an array in order of date. The stock profit is the difference in prices in buying and selling stock. Each day, you can either buy one unit of stock, sell any number of stock units you have already bought, or do nothing. Therefore, the most profit is the maximum difference of all pairs in a sequence of stock prices.

@param {array} quotes
@return {number} max profit

Example:

 [ 1, 2, 3, 4, 5, 6 ]        => 15  (buy at 1,2,3,4,5 and then sell all at 6)
 [ 6, 5, 4, 3, 2, 1 ]        => 0   (nothing to buy for profit)
 [ 1, 6, 5, 10, 8, 7 ]       => 18  (buy at 1,6,5 and sell all at 10)
 [ 1, 2, 10, 3, 2, 7, 3, 2 ] => 26  (buy at 1,2 and sell them at 10. Then buy at 3,2 and sell them at 7)

(c)RSS

Puzzles

Stats:

CreatedJul 31, 2017
PublishedJul 31, 2017
Warriors Trained3669
Total Skips118
Total Code Submissions7132
Total Times Completed1175
JavaScript Completions465
F# Completions7
Python Completions506
C# Completions100
Haskell Completions28
C Completions29
Rust Completions41
C++ Completions66
COBOL Completions5
Go Completions15
NASM Completions5
D Completions4
Total Stars104
% of votes with a positive feedback rating93% of 211
Total "Very Satisfied" Votes186
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes4
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • arhigod Avatar
  • JohanWiltink Avatar
  • neilm Avatar
  • rowcased Avatar
  • hobovsky Avatar
  • albertogcmr Avatar
  • Expurple Avatar
  • akar-0 Avatar
  • Aiden2207 Avatar
  • dfhwze Avatar
Ad