Question: [Algorithm Analysis] Suppose your younger brother have started a new business where he buys a new product and sell that product on a day when

[Algorithm Analysis]

Suppose your younger brother have started a new business where he buys a new product and sell that product on a day when he gets the maximum prot.

Your brother isnt a very good mathematician, and is also very impatient about selling the product. So you need to help him and suggest him the days of buying and selling the product where he can earn the maximum prot. But you do not have enough time to invest in his business, so you have decided to write a program for him.

Input: You are given an array where the price of the product on different days are given like this: [7,1,5,3,6,4]

You need to write the algorithm in a proper sequence where it can nd out the buying and selling days so that your brother can earn the maximum prot. Mention if you can apply any well known algorithm to solve this problem.

The answer for the given array would be buying day2m1 and selling day6th. Because if your brother buys the product on the 2ndl day and sells it on the 6th day, he can earn the maximum prot of 5.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!