Leecode 122. Best Time to Buy and Sell Stock II (C,C++,C#,JAVA,JAVASCRIPT,TYPESCRIPT,RUBY)

Say you have an array prices for which the ith element is the price of a given stock on day i.

Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).

Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).

Example 1:

Example 2:

Example 3:


  • 1 <= prices.length <= 3 * 10 ^ 4
  • 0 <= prices[i] <= 10 ^ 4




student at Flatiron School

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How does ServiceNow Admin deal with ServiceNow Problem Management?

5 Wrong Ways To Save Money

Query your Tableau view data like a boss using Python and Pandas


Self Sizing TableView Cells

Revoking tokens in Azure AD B2C

Revoked image

SQL Server — Lazy writer

Palindrome in Java: How to check a number or string?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chan Park

Chan Park

student at Flatiron School

More from Medium

Amazon Online assesment

Interview coding questions

oops in java:

Retired Programmer Tries AI Programming in Python. 05) Development — Basic Setup

The Weekend Newsletter