DEV Community

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

Posted on

1

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!

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE