DEV Community

Cover image for Interview Practice: Buy and Sell Stock Problem
Marius Espejo
Marius Espejo

Posted on

Interview Practice: Buy and Sell Stock Problem

Visual learners this is for you!

Challenge:

You are given an array of integers which represent the price of a stock on a given day.

You want to MAXIMIZE your profit by choosing a single day to buy one stock and choosing a DIFFERENT day in the future to sell that stock.

Return the MAXIMUM PROFIT you can achieve from this selling transaction.

In this video I'm going to show you the different approaches to tackle this problem, starting with a basic brute force approach, then switching to something a bit more optimized using some intuition that we gather from some visuals.

Let me know what you think!

πŸš€ πŸ’Ž πŸ‘

Top comments (0)