Skip to content

Instantly share code, notes, and snippets.

@robconery
Created September 27, 2023 19:15
Show Gist options
  • Save robconery/cffc8c2fb5c37adf503abba6c5b557eb to your computer and use it in GitHub Desktop.
Save robconery/cffc8c2fb5c37adf503abba6c5b557eb to your computer and use it in GitHub Desktop.
Mission Stock Price

OK grab your journal and dive in with me! I'll be solving this question by hand I urge you to do the same. I'll show you the solution near the end - but give it your best shot!

This question is from InterviewCake - thanks to Parker Phinney for permission to use. You can solve it there right now, if you like, as it’s part of the free questions.

Here’s the question:

Write an efficient function that takes stockPricesYesterday and returns the best profit I could have made from 1 purchase and 1 sale of 1 Apple stock yesterday.

Starter code:

//The values are the price in dollars of Apple stock at that time.
var stockPricesYesterday = [10, 7, 5, 8, 11, 9];

getMaxProfit(stockPricesYesterday);
// returns 6 (buying for $5 and selling for $11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment