Given a series of positive integers representing the prices of a single stock on various days (in the array each index represents a different day). Also, there is a list that represents the number of actions you are allowed to take. integer is given. A transaction is the purchase of a stock on a particular day and another day the next. is sold on the date. Returns the maximum profit you can make by buying and selling stocks, given X trades. will be written in c# code write a function. Note that you can only own one share of the stock at a time; in other words, You cannot buy more than one share of the stock on any given day and still have another share. You cannot buy a share of the stock if you own it. Also, all allowed x operations You don't need to use it. will be written in c# code sample entry: prices = [5, 11, 3, 50, 60, 90] x = 2 sample output: 93 // Buy: 5, Sell: 11; Buy: 3, Sat: 90 This is how the code will be written: public static int Max Profit in Trading(int[] prices, int Number of Transactions, out int[] Trades) { // code return -1; } write a function. Note that you can only own one share of the stock at a time; in other words, You cannot buy more than one share of the stock on any given day and still have another share. You cannot buy a share of the stock if you own it. Also, all allowed x operations You don't need to use it.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter5: Making Decisions
Section: Chapter Questions
Problem 4PE
icon
Related questions
Question

Given a series of positive integers representing the prices of a single stock on various days (in the array
each index represents a different day). Also, there is a list that represents the number of actions you are allowed to take.
integer is given. A transaction is the purchase of a stock on a particular day and another day the next.
is sold on the date.
Returns the maximum profit you can make by buying and selling stocks, given X trades.

will be written in c# code

write a function.
Note that you can only own one share of the stock at a time; in other words,
You cannot buy more than one share of the stock on any given day and still have another share.
You cannot buy a share of the stock if you own it. Also, all allowed x operations
You don't need to use it.

will be written in c# code

sample entry:
prices = [5, 11, 3, 50, 60, 90]
x = 2
sample output:
93 // Buy: 5, Sell: 11; Buy: 3, Sat: 90


This is how the code will be written:
public static int Max Profit in Trading(int[] prices, int Number of Transactions, out int[] Trades) {
// code
return -1;
}

write a function.
Note that you can only own one share of the stock at a time; in other words,
You cannot buy more than one share of the stock on any given day and still have another share.
You cannot buy a share of the stock if you own it. Also, all allowed x operations
You don't need to use it.

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning