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
Similar Kata:
Stats:
Created | Jul 31, 2017 |
Published | Jul 31, 2017 |
Warriors Trained | 3669 |
Total Skips | 118 |
Total Code Submissions | 7132 |
Total Times Completed | 1175 |
JavaScript Completions | 465 |
F# Completions | 7 |
Python Completions | 506 |
C# Completions | 100 |
Haskell Completions | 28 |
C Completions | 29 |
Rust Completions | 41 |
C++ Completions | 66 |
COBOL Completions | 5 |
Go Completions | 15 |
NASM Completions | 5 |
D Completions | 4 |
Total Stars | 104 |
% of votes with a positive feedback rating | 93% of 211 |
Total "Very Satisfied" Votes | 186 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 8 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |