Open In App

Stock Buy and Sell Problems with Variations

Last Updated : 13 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

You might have encountered a lot of problems where the user can buy and sell stocks with certain restrictions. In this article, we are going to list all such variations of Stock Problems.

  1. Stock Buy and Sell when at most one transaction is allowed:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We can buy a stock at any day and sell it on any other day after buying, with the only restriction that we can only buy and sell the stock at most once. The task is to maximize the profit by buying and selling the stock at most once.

  2. Stock Buy and Sell when at most two transactions are allowed:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We can buy a stock at any day and sell it on any other day after buying, with the only restriction that we can only buy and sell the stock at most twice. The task is to maximize the profit by buying and selling the stock at most twice.

  3. Stock Buy and Sell when at most K transactions are allowed:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We can buy a stock at any day and sell it on any other day after buying, with the only restriction that we can only buy and sell the stock at most K times. The task is to maximize the profit by buying and selling the stock at most K times.

  4. Stock Buy and Sell when Infinite transactions are allowed:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We can buy a stock at any day and sell it on any other day after buying. Unlike the previous variations, we can buy and sell the stock any number of times. The task is to maximize the profit by buying and selling the stock any number of times.

  5. Stock Buy and Sell with Cooldown:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We can buy a stock at any day and sell it on any other day after buying. In this variation, we can buy and sell stocks any number of times, but there is a cooldown after every transaction. It means that if we sell a stock at i-th day, then we cannot buy any stock for another D days where D is the cooldown period. The task is to maximize the profit by buying and selling the stock any number of times considering the cooldown period.

  6. Stock Buy and Sell with Transaction Fee:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We can buy a stock at any day and sell it on any other day after buying. Similar to the last variation, we can buy and sell stocks any number of times, but there is a transaction fee incurred after every transaction. It means that we need to pay the transaction fee for every stock we sell. The task is to maximize the profit by buying and selling the stock any number of times considering the transaction fee.

  7. The Stock Span Problem:

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. We need to calculate the span of the stock for every day. The span of the stock for i-th day is defined as the maximum number of consecutive days that have passed starting from the i-th day for which the stock price was less than the i-th day. The task is to find the span of the stock for all the days.

  8. Buy Maximum Stocks if i stocks can be bought on ith day

    In this problem, we are given an array prices[], where prices[i] denotes the price of stock on i-th day. In this variation, we have a limitation that we can buy at most i stocks on the i-th day. Our goal is to maximize the total number of stocks we can buy if we have a fixed amount of money.

Below is a table consisting of all the variations of Stock Problems:

Problem

Practice Link

Stock Buy and Sell with at most one transaction

Practice Now

Stock Buy and Sell with at most two transactions

Practice Now

Stock Buy and Sell with Infinite transactions

Practice Now

Stock Buy and Sell with at most K transactions

Practice Now

Stock Buy and Sell with Cooldown

Practice Now

Stock Buy and Sell with Transaction Fee

Practice Now

The Stock Span Problem

Practice Now

Buy Maximum Stocks if i stocks can be bought on i-th day

Practice Now



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads