person is trading his money in the stock exchange market. Assume that the daily price of a specific market along a certain period of time is given as follows: Price [200, 500, 800,100, 300, 50] all in Dollar. This means that the price of the stock in the first day is 200$ and the day after which is mean the second day the price is going up to be $500 and so on A

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 18PE
icon
Related questions
Question

note : Build your algorithm by using OUBUILD or scratch

A person is trading his money in the stock exchange market. Assume that the daily price of a specific
market along a certain period of time is given as follows:
Price [200, 500, 800,100, 300, 50] all in Dollar. This means that the price of the stock in the first day
is 200$ and the day after which is mean the second day the price is going up to be $500 and so on
until the end of the week or the list you are given. You are allowed to buy and sell the stock only
once, which means that if you buy it on the first day then you will pay 200$ then if you decided to
sell it on the third day then you will get $800 the your profit will be $600.
Another example:
prices = {300, 450, 720, 90, 30, 50, 900,
500, 70};
Output:
Buying date: day 5, at the price of $30
selling date: day 7, at the price of $900
Maximum Profit: $870
1. You are requested to develop an algorithm to maximize the profit in single buy and sell.
Transcribed Image Text:A person is trading his money in the stock exchange market. Assume that the daily price of a specific market along a certain period of time is given as follows: Price [200, 500, 800,100, 300, 50] all in Dollar. This means that the price of the stock in the first day is 200$ and the day after which is mean the second day the price is going up to be $500 and so on until the end of the week or the list you are given. You are allowed to buy and sell the stock only once, which means that if you buy it on the first day then you will pay 200$ then if you decided to sell it on the third day then you will get $800 the your profit will be $600. Another example: prices = {300, 450, 720, 90, 30, 50, 900, 500, 70}; Output: Buying date: day 5, at the price of $30 selling date: day 7, at the price of $900 Maximum Profit: $870 1. You are requested to develop an algorithm to maximize the profit in single buy and sell.
Expert Solution
steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
Matrix multiplication
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
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