Back to Browse

DSA Problem 012: Maximum Profit

15 views
Nov 30, 2025
6:17

#dsa #javascript Github: https://github.com/therajatg/DSA/blob/main/012-max-profit.js Best Time to Buy and Sell Stock You are given an integer array prices where prices[i] is the price of a stock on the ith day. You may choose a single day to buy the stock and choose a different day in the future to sell it. Return the maximum profit you can achieve. You may choose to not make any transactions, in which case the profit would be 0. Example 1: Input: prices = [10,1,5,6,7,1] Output: 6 Explanation: Buy prices[1] and sell prices[4], profit = 7 - 1 = 6. Example 2: Input: prices = [10,8,7,5,2] Output: 0 Explanation: No profitable transactions can be made, thus the max profit is 0.

Download

0 formats

No download links available.

DSA Problem 012: Maximum Profit | NatokHD