This video is free to watch - hope you enjoy it! If you like what you see, there's a ton more where that came from...

Sign Up

Practice: Stock Price Calculation

This is a real interview question that comes straight from Amazon. You'll be writing this one by hand so remember your strategies.

This content is for subscribers only - which you can become in just 30 seconds!

Sign Up

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)
  • Get to Know Big-O

    It's a thing you'll need to know if you plan to get through any interview. It's actually quite useful and in this post I'll hopefully make the case that's it's simple as well.

  • Getting Past the Screener

    Before you get to the white board you'll likely have to pass an introductory screening interview - a short call (or in person meeting) to suss out what you know.

  • Databases: How Would You Implement...?

    Screener questions tend to have a bit more broad and, typically, based on your experience... sometimes not. Think about how you would answer this one about databases.

  • JavaScript: What Time Is It?

    Sometimes a potential interviewer will 'cosplay' with you - pretending that you work at the company and seeing how you might solve one of their realworld problems.

  • Your Interview Mindset

    You're not going to make it through this section unless you have the right frame of mind. Simply wanting a job isn't enough - you need to calm yourself and focus.

  • Understanding the Mechanics of The Interview Question

    Don't hate me... and PLEASE don't skip this video. Let's walk through Fibonacci together as a way of understanding how interviewers will flex and extend a single question to dig into your brain.

  • Practice: Stock Price Calculation

    This is a real interview question that comes straight from Amazon. You'll be writing this one by hand so remember your strategies.

  • Practice Question: Product of All Numbers But This

    A straightforward problem that, at first, seems daunting - until you break it down and apply the strategies you know.

  • Practice Question: Smallest Range of K Lists

    This is a tough one and you might struggle with it some. If you do, practice speaking aloud to get help from the interviewer.

  • Jon Skeet: Creating a C# Linter

    Another traditional question: create a linter for X language. This is more about parsing a string and remembering where you are within it.

  • Jon Skeet: Falling From Great Heights

    Not all interview questions have to do with code - some are purely logical, designed to see how you would try and solve a really, really hard problem. Skeet couldn't figure this one out...

  • Jon Skeet: Binary Tree Troubles

    It's a rule of interviews: 'ask a binary tree question' and that's exactly what I do in this video with Jon. Traversing in different ways, trying to balance along the way.

  • Jon Skeet: Creating a Queue from Scratch

    This is another very popular question from larger companies, and requires you to be familiar with linked lists, arrays and stacks.

  • Jon Skeet: Anagram Checker

    Let's end things with one that's a bit simpler - creating a string walking function that evaluates anagrams.

Watch Again

[[prev.title]]

[[prev.summary]]

Next Up

[[next.title]]

[[next.summary]]